I think I've solved it. fork won't apply to all threads in a process, only the thread calling fork will be forked. The golang-runtime-environment has been destroyed after fork. So if I want to fork a binary staticly linked to a go lib. I have to use golang-style fork. That means run program again with the same parameters, and terminate self. So tricky and only the engineers as smart as me can figure it out independently and solve.
在 2017年9月16日星期六 UTC+8下午5:09:48,wolfk...@gmail.com写道: > > I found golang gc will hang when started from a daemonlized c++ program. > But fine if not daemonlized. > > 在 2017年9月13日星期三 UTC+8上午1:22:35,Ian Lance Taylor写道: >> >> On Tue, Sep 12, 2017 at 9:52 AM, <wolfk...@gmail.com> wrote: >> > >> > To be precise, I want to know if the garbage-collection thread still >> runs if >> > the program is started from C++ main-entry. >> > I think a pure golang program will start the gc-thread before the 'func >> > main(){}' but I don't know if it still holds true if the golang-part >> is >> > only a static-library. >> >> It's not precisely accurate to see that there is a garbage-collection >> thread (there is a "system monitor" thread) but it is accurate to say >> that Go garbage collection works in parallel when linked into a C >> program just as it does in a normal Go program. The Go runtime will >> start threads as needed either way. >> >> Ian >> >> > 在 2017年9月13日星期三 UTC+8上午12:42:15,wolfk...@gmail.com写道: >> >> >> >> By using cgo, I wrappered some complex code written by golang into a >> >> static-lib and call into the lib >> >> from C++. >> >> My question is: the process will run from a c++ main-entry. Will >> golang's >> >> gc-background thread work in this way? I'm worried that the entry is >> from >> >> C++ code and golang's vm-environment may not be complete so that gc >> won't >> >> work and there will be memory-leaks. >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "golang-nuts" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an >> > email to golang-nuts...@googlegroups.com. >> > For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.