Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2007-09-03 10:24:20


Rene Tarantino wrote:

> Hi:
>
> I'm having a bit of trouble with the implementation of the monitor
> pattern by means of using mutex and condition classes.
>
> I have a scheduler thread and a group of worker threads and the
> scheduling algorithm waits until some worker notifies that it has done
> the job.
>
> It seems that the call to condition::notify_one() must be in a
> specific order because if the worker calls notify_one before the
> scheduler arrives to the waiting line it behaves as if the condition
> object has lost the previous call to notify_one.

You haven't posted any code, but from what you say above it seems you
believe that notify_one is "sticky". It's not -- it only wakes a
thread that is already waiting on a condition variable. So, 'notify_one'
and 'notify_all' should be viewed as 'something changed' notification, and
you should maintain all 'interesting' state yourself, and check it like this:

        while(!something_interesting)
                cond.wait()

- Volodya


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