Boost logo

Boost Users :

Subject: [Boost-users] Subject::[boost thread] does a thread block itself when it passes the conditional variable to another thread?
From: Lei (oddo) Zhang (lzha174_at_[hidden])
Date: 2008-12-08 04:49:39


inside a thread, if the conditional variable is changed to satisfy another
thread which is on the waiting thread list. Does the current thread give up
the global mutex and blocks itself until another thread gives up the mutex?

boost::mutex mutex;
boost::condition cond;
bool data_ready=false;
:
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?

}

void thread2(){
    boost::mutex::scoped_lock lock(mutex);
     while ( !data_ready)
     {
         cond.wait(lock);
     }
    ....//do work
}

-- 
Lei(Oddo) Zhang
70 Symonds Street
Engineering Science Department


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