Reputation: 306
I'm using Poco::ServerApplication
and Poco::TaskManager
at the same time and encountered a wired problem.
If start without --daemon
option, everything is ok. However when start with --daemon
, the task passed to the taskmanager is never started. I debugged it with gdb and found that when with --daemon
option, threads in the taskmanager's inner taskpool were started and soon stopped. So when calling TaskManager::start
, it just uses an already finished thread and thus the task is never started.
I wonder if this is because of any restriction to a linux daemon, or is there anything else will cause this problem?
Here is the sample code which can reproduce the problem on my box.
http://codepaste.net/jhoyt5
Sorry for my poor English :P. And I would appreciate any ideas?
Upvotes: 1
Views: 1499
Reputation: 1
I had this same Problem. I actually wasn't starting the threads in the constructor, but was creating the Poco::TaskManager container in the constructor. Once I created it in my main() everything worked.
Upvotes: 0
Reputation: 41
From the official ServerApplication documentation:
New threads must only be created in initialize() or main() or methods called from there, but not in the application class' constructor or in the constructor of instance variables. The reason for this is that fork() will be called in order to create the daemon process, and threads created prior to calling fork() won't be taken over to the daemon process.
Upvotes: 4