Creating a thread and blocking its execution
Hello, I use boost::thread as follow: mp_Thread = new boost::thread(boost::bind(CSubsystem::TaskWrapper, this)); to create a thread in an initialization method. I observe that this thread gets to run before my initialization method has completed its execution. I would like to create a thread from this initialization method, and wait for it to execute until the whole initialization process it done. Is it possible to create a thread in suspended mode, and then release it once the system is ready? Or do I need to use a synchronization mechanism like a semaphore to release it? Jean-Sebastien
On Tue, Aug 31, 2010 at 7:31 PM, Jean-Sebastien Stoezel
I would like to create a thread from this initialization method, and wait for it to execute until the whole initialization process it done.
I would use a condition variable plus a boolean state (a primitive event) that is passed to the thread-function upon creation (utilizing boost::bind). thread waits for the condition to be signaled. the initialization routine updates the state and notifies the condition upon completion. If you need this pattern frequently, I'd suggest to extract that logic from CSubsystem::TaskWrapper into common class. Best regards, Christoph
Hello, Thanks for advice and the quick reply. Jean-Sebastien On Tue, Aug 31, 2010 at 2:14 PM, Christoph Heindl < christoph.heindl@gmail.com> wrote:
On Tue, Aug 31, 2010 at 7:31 PM, Jean-Sebastien Stoezel
wrote: I would like to create a thread from this initialization method, and wait for it to execute until the whole initialization process it done.
I would use a condition variable plus a boolean state (a primitive event) that is passed to the thread-function upon creation (utilizing boost::bind). thread waits for the condition to be signaled. the initialization routine updates the state and notifies the condition upon completion.
If you need this pattern frequently, I'd suggest to extract that logic from CSubsystem::TaskWrapper into common class.
Best regards, Christoph _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello,
I use boost::thread as follow:
mp_Thread = new boost::thread(boost::bind(CSubsystem::TaskWrapper,
On Tuesday, August 31, 2010 1:31 PM, Jean-Sebastien Stoezel wrote: this));
to create a thread in an initialization method. I observe that this
thread
gets to run before my initialization method has completed its execution.
I would like to create a thread from this initialization method, and wait for it to execute until the whole initialization process it done. Is it possible to create a thread in suspended mode, and then release it once the system is ready? Or do I need to use a synchronization mechanism like a semaphore to release it?
Jean-Sebastien
What prevents you from creating the thread as the last step in your initialization method?
participants (3)
-
Andrew Holden
-
Christoph Heindl
-
Jean-Sebastien Stoezel