Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2000-08-11 17:30:06

--- In boost_at_[hidden], jsiek_at_l... wrote:
> William Kempf writes:
> > Your code did give me an idea, however. I've been trying to
> > out how you could tie the CV to the mutex and also require the
> > to be locked before calling wait. Well, you could pass the
mutex in
> > to the CVs constructor for the first part, and place the wait()
> > method in the lock, passing in the CV, for the second part.
> > still have some pretty tight coupling in my mind with the lock
> > needing to be a friend of the mutex and the CV a friend of the
> > but it seems "solid" to me at this point.
> I have trouble understanding english (even though that's my native
> lang). I understand C++ much better :) Code examples please!

Maybe it's me that has trouble writing english even though it's my
native language ;).

Well, I'm still struggling a little on the tight coupling issues, so
I don't have a full implementation of the idea yet. However, I can
give example code to illustrate what I'm thinking.

mutex mx;
condition cv(mx);
mutex::lock lock(mx);

while (!full) // Just to not cloud things with the predicate

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

Boost list run by bdawes at, gregod at, cpdaniel at, john at