
In boost::thread, when a thread is created, it starts execution at
On Thursday, July 15, 2010 2:53 PM Bill Buklis wrote: that
instance itself. Instead of this, is it possible to postpone the execution?
No. You can have the thread function block on a condition variable or something straight away though. That way you can control when it resumes by setting the flag and notifying the condition variable.
I know that this can be easily done in Windows with the CREATE_SUSPENDED flag. Can this be done in boost::thread? If not, I would consider this a big limitation. Do other operating systems support this? Surely, Windows isn't the only one. On that note does boost::thread support suspending and resuming thread execution? I haven't used boost::thread (only native Windows calls), so I don't know.
An examination of https://computing.llnl.gov/tutorials/pthreads indicates that Posix threads (used by the UNIX family of operating systems, including Linux and MacOS-X) does not support suspending threads either at creation or later. Also, Microsoft has found that the SuspendThread function is dangerous (see http://msdn.microsoft.com/en-us/library/ms686345%28VS.85%29.aspx). If you desire the ability to suspend a thread, it is best to have it wait on something.