Condition variables?

Janice Caron caron800 at googlemail.com
Tue Oct 2 09:08:56 PDT 2007


On 10/2/07, David Brown <dlang at davidb.org> wrote:
> Aside from the fact that the example isn't quite right (see my other
> posting), condition variables _must_ be taken inside of a synchronize
> statement.  The underlying condition variable requires a mutex as well as
> the condition variable.  The wait operation atomically unlocks the mutex
> and goes to sleep.  Upon re-awakening, it then reacquires the lock without
> allowing someone else to sneak in.

Aha! Thanks. Well, I freely admit my ignorance concerning condition
variables. (I've never used them).


> This feature is the very magic about condition variables that makes race
> free synchronization possible where it isn't with events.

Now that part is not right. Race-free synchronization is /always/
possible with events. (Note, however, that I say "possible", not
"guaranteed". There's nothing to stop you writing crap code). That
Queue class of yours could easily be done with events, and race-free
too, but the pseudo code would look quite different.

I guess it's just what you're used to.



More information about the Digitalmars-d mailing list