|
Boost : |
From: jsiek_at_[hidden]
Date: 2000-08-11 17:40:04
William Kempf writes:
> mutex mx;
> condition cv(mx);
> mutex::lock lock(mx);
>
> while (!full) // Just to not cloud things with the predicate
> lock.wait(cv);
>
> You obviously can't wait on the cv unless the mutex is locked. Since
> both the lock and the CV were constructed with the mutex it's
> possible to throw an exception if the two aren't associated with the
> same mutex (not as good as a compile time error, but better than
> nothing).
Or how about this:
mutex mx;
condition cv; // no mutex here
mutex::lock lock(mx);
while (!full)
lock.wait(cv); // mutex comes from the lock
Now it is impossible for the user to use the wrong mutex with the
codition variable.
-Jeremy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk