问题
Problem:
Call/Initialize Poco code from inside a C library, using loader (3rd party C program, our code is in c++).
- The Program loads our library, our lib initializes Poco::Logger and uses AsyncChannel + FileChannel in the logger.
- Fork from this process.
- Run some threads in the child process.
- try to exit the child process, joining threads.
- The AsyncChannel's destructor blocks on close(), essentially polling Queue and sleeping.
- The _queue has 1 element always when the destructor for AsyncChannel is called, and I assume that is due to the way the parent process is running and forking.
Now the question: Is this a problem with gcc that Forking a process does not call the constructors and just duplicates the memory? I have tried calling _queue.clear() inside AsyncChannel::AsyncChannel() but no results...
Has anyone seen this problem before? any proposed solution?
回答1:
Response here:
http://pocoproject.org/forum/viewtopic.php?f=10&t=6378
Summary: create threads after fork and not before. Same problem with Poco::Util::Timer and other classes also.
来源:https://stackoverflow.com/questions/26998019/poco-asyncchannel-does-not-exit-on-forked-process-exit