golang/go

runtime/cgo: call C exit to allow global destructors/atexit to run

Open

#20,713 opened on 2017年6月17日

GitHub で見る
 (8 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsFixUnfortunatehelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (30d に merged PR はありません)

説明

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/go" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build855140157=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1" PKG_CONFIG="pkg-config" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2"

What did you do?

I want to do something in the destructor of a global variable defined in c++ library which is linked into a go program via cgo. but the destructor can't be invoked when the go program exited.

//c++ library class AutoInit { public: AutoInit() { printf("+++++ auto init\n"); } ~AutoInit() { printf("---- auto fini\n"); } };

What did you expect to see?

two lines should be printed: +++++ auto init ---- auto fini

What did you see instead?

only one line was be printed: +++++ auto init

コントリビューターガイド