|
Boost Users : |
Subject: Re: [Boost-users] Subject::[boost thread] does a thread block itself when it passes the conditional variable to another thread?
From: Igor R (boost.lists_at_[hidden])
Date: 2008-12-08 11:06:33
>
> void thread1(){
> boost::mutex::scoped_lock lock(mutex);
>
> ...//do some work
> data_ready=true;
> cond.notify_one() //assume the condition is satisfied.
> //do more work -------my question is will this part continue? or
> thread2 will wake up and block thread 1?
>
> }
>
The thread1() will continue and the thread2() will be still locked. If you
wish to avoid this situation, you have to unlock the mutex manually before
the notification:
lock.unlock();
cond.notify_one();
...as explained here:
http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html
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