Condition variables?

Steven Schveighoffer schveiguy at yahoo.com
Wed Oct 3 08:20:06 PDT 2007


"Graham St Jack" wrote
> Steven Schveighoffer wrote:
>> 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.
>
> If you read the source for the Condition class under the example, you will 
> see that all it does is sets the Condition's satisfied member, possibly 
> signaling the underlying pthread_condition_t. Putting this boolean into 
> the Condition class makes it FAR easier to avoid coding errors.

Doh!  Another case of not reading the whole post, I didn't see that the 
Condition variable was implemented underneath the example code.

I see what it means:

ready(condition)

is equivalent to:

if(condition)
  ready();

Interesting concept, so instead of the waiting thread deciding whether the 
condition is satisfied, the signalling thread decides.  Personally, I'd put 
a test around the wait statement too in case another thread signalled with a 
different reason, just to be sure, but I can see how it works now.

-Steve 





More information about the Digitalmars-d mailing list