
I plan to start using Boost Thread, but for now I have a multithreaded Win32 application that does not use boost. Although the threads were not created with Boost Thread, can I use boost::mutex::scoped_lock to protect some new functions I write for the app? Example: boost::mutex mutex; void whatever() { boost::mutex::scoped_lock lock(mutex); // will this be protected even though the // thread was not created using Boost? } Thank you

AMDG On 02/21/2013 05:22 PM, Jeff Dunlap wrote:
I plan to start using Boost Thread, but for now I have a multithreaded Win32 application that does not use boost.
Although the threads were not created with Boost Thread, can I use boost::mutex::scoped_lock to protect some new functions I write for the app?
Yes. Synchronization primitives should work on any thread regardless of whether it was started using Boost.Thread or not. (I should point out that the main thread is never started by Boost.Thread, so this /has/ to work.)
Example:
boost::mutex mutex;
void whatever() { boost::mutex::scoped_lock lock(mutex); // will this be protected even though the // thread was not created using Boost? }
In Christ, Steven Watanabe

Le 22/02/13 04:45, Steven Watanabe a écrit :
AMDG
I plan to start using Boost Thread, but for now I have a multithreaded Win32 application that does not use boost.
Although the threads were not created with Boost Thread, can I use boost::mutex::scoped_lock to protect some new functions I write for the app? Yes. Synchronization primitives should work on any thread regardless of whether it was started using Boost.Thread or not. (I should
On 02/21/2013 05:22 PM, Jeff Dunlap wrote: point out that the main thread is never started by Boost.Thread, so this /has/ to work.) I confirm.
Example:
boost::mutex mutex;
void whatever() { boost::mutex::scoped_lock lock(mutex); // will this be protected even though the // thread was not created using Boost? }
The nested class scoped_lock is deprecated. Could I suggest you to use lock_guard/unique_lock classes? boost::lock_guardboost::mutex lock(mutex); Best, Vicente
participants (3)
-
Jeff Dunlap
-
Steven Watanabe
-
Vicente J. Botet Escriba