Poco AsyncChannel does not exit on forked process

2019-09-07 05:23发布

Problem:

Call/Initialize Poco code from inside a C library, using loader (3rd party C program, our code is in c++).

  1. The Program loads our library, our lib initializes Poco::Logger and uses AsyncChannel + FileChannel in the logger.
  2. Fork from this process.
  3. Run some threads in the child process.
  4. try to exit the child process, joining threads.
  5. The AsyncChannel's destructor blocks on close(), essentially polling Queue and sleeping.
  6. 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条回答
Explosion°爆炸
2楼-- · 2019-09-07 05:58

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.

查看更多
登录 后发表回答