Condition variables?

Sean Kelly sean at f4.ca
Tue Oct 2 09:14:47 PDT 2007


Steven Schveighoffer wrote:
> 
> So the code above has to do something special by unlocking the object before 
> waiting using an atomic operation.  I think this requires some language 
> support.

Doing this efficiently typically requires OS support.  The library must 
indicate to the OS that a context switch may not occur while certain 
portions of the code are executing.  It is possible to implement 
condvars without OS support as well, but the implementation tends to be 
fairly complicated.  Look for version(Win32) blocks in the Tango 
implementation for one such example.

> BTW, I'm not sure what the ready(count > 0) function does?  Can someone 
> explain it?  It appears that it is the signal, but I'm not sure why the 
> condition is required.

That call encapsulates some of the logic normally written by hand in 
mutex/condition blocks.  The "count > 0" is the boolean operation to be 
evaluated.  Personally, I think it's kind of an odd design.


Sean



More information about the Digitalmars-d mailing list