Boost logo

Boost :

From: duncan_at_[hidden]
Date: 2001-07-02 08:56:07

paquette_at_[hidden] (Jeff Paquette) wrote:

> PMFJI, but doesn't this (Win32 pseudo code):
> WaitForSingleObject(mutex);
> .. do work ..
> WaitForMultipleObjects(mutex, event, wait_all);
> .. do more work ..
> ReleaseMutex(mutex);
> ReleaseMutex(mutex);
> work in the same fashion as the monitor mentioned above sans race
> condition?

No. The inclusion of mutex again in your second wait has no effect
since you already own it. The pattern requires atomically releasing the
mutex and entering the wait state. You can easily do this with the
SignalObjectAndWait() function, but that is only available on NT/2K/XP.
A portable version requires more complicated logic.

Schmidt and Pyarali have written about this:

Duncan Harris, Sapio Design Ltd, Manchester, U.K.

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