|
Boost Users : |
From: Pete Chapman (p.chapman_at_[hidden])
Date: 2005-10-25 03:46:45
condition::wait requires that a lock is acquired prior to calling it,
but condition::notify does not.
The Java threading API (which in my limited experience seems similar to
boost::thread) requires that a lock is acquired prior to calling
Object.notify().
Is this potentially a problem? For example:
scoped_lock myLock(myMutex);
while (!some_variable)
{
// Another thread now sets some_variable = true, and
// calls myCondition.notify()
// then...
// will this wait indefinitely?
myCondition.wait(myLock);
}
Clearly if the other thread in this example were forced to obtain a lock
on myMutex before calling myCondition.notify(), there would be no
danger. In practice this is what I do anyway, but the boost:thread API
doesn't force me to. Why not? Is there a potential problem if I don't?
Many thanks...
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