Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-08-13 15:20:13


From: "Scott McCaskill" <scott_at_[hidden]>
> ----- Original Message -----
> From: "Peter Dimov" <pdimov_at_[hidden]>
> > What is the scenario? I can see the code and I think I understand it,
but
> > what is it supposed to do, and is this a common example? One thing
that's
> > not apparent from the code is whether notifyThread() is supposed to be
> > "thread-safe" as well, i.e. are multiple threads allowed to concurrently
> > call notifyThread.
>
> The scenario here is that you have one or more threads issuing commands to
> one or more worker threads who receive the commands and act accordingly.
So
> yes, multiple threads may call notifyThread() concurrently. I think this
> may be one of the most common examples of the uses of CVs.

And, presumably, I don't care which worker thread will handle the command?

[...]

> > But this doesn't handle termination.
>
> bool done = false;
>
> void threadfunc()
> {
> for(;;)
> {
> int command;
> {
> mutex::scoped_lock lock( m );
> while(q.empty() && !done)
> cv.wait( lock );
> if ( done ) break;
> command = q.pop();
> }

[...]

Of course, but we've come full circle now. Is the added complexity worth it?
CVs are good, nobody's disputing that. Why are events not worthy for
inclusion, is the question.

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk