Boost logo

Boost Users :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2006-12-14 09:58:10


Ovanes Markarian wrote:
> Hi!
>
> you could define a scope where to lock ;) Just like this:
>
>
> boost::mutex a_mutex;
> ...
> {
> {
> boost::mutex::scoped_lock lock(a_mutex); //lock
> cout<<"bla";
> }//end of scope => unlock
>
> //much of code where cout dont has to be locked
> ...
> }

Or:

foo()
{
        boost::mutex::scoped_lock lk(a_mutex);
        cout << "bla" ;
        lk.unlock();
         .... some other stuff unlocked
             lk.lock(); // lock again
        .....

}

The lock is (conditionally) unlocked however when you leave the scope.

Roland


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