|
Boost Users : |
Subject: Re: [Boost-users] scope_lock question
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-02-22 01:46:18
Le 22/02/13 04:45, Steven Watanabe a écrit :
> 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.)
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_guard<boost::mutex> lock(mutex);
Best,
Vicente
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net