Condition variables?

Sean Kelly sean at f4.ca
Tue Oct 2 10:28:26 PDT 2007


Janice Caron wrote:
> On 10/2/07, Sean Kelly <sean at f4.ca> wrote:
>> Janice Caron wrote:
>>> Now that part is not right. Race-free synchronization is /always/
>>> possible with events. (Note, however, that I say "possible", not
>>> "guaranteed".
>> How so?
> 
> class ThreadsafeQueue(T)
> {
>     Event e;
> 
>     this()
>     {
>         e = new Event;
>     }
> 
>     sychronized void opCat(T x)
>     {
>         add_item_to_queue;
>         e.signal;
>     }
> 
>     T remove()
>     {
>         T x;
>         for (;;)
>         {
>             e.wait;
>             synchronized(this)
>             {
>                 if (queue.length != 0)
>                 {
>                     x = remove_item_from_queue;
>                     e.signal;
>                     return x;
>                 }
>             }
>         }
>     }
> }

That pseudocode doesn't help much, I'm afraid.  Is this an auto or 
manual reset event?  Is PulseEvent or SetEvent being called by e.signal?

>> Win32 events are widely regarded as broken on
>> comp.programming.threads
> 
> That's prejudice for you.

I'm not sure that prejudice has a lot to do with it.  They complain 
about pthreads nearly as often, though for different reasons.


Sean



More information about the Digitalmars-d mailing list