Condition variables?

Janice Caron caron800 at googlemail.com
Tue Oct 2 10:16:34 PDT 2007


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;
                }
            }
        }
    }
}


> Win32 events are widely regarded as broken on
> comp.programming.threads

That's prejudice for you.



More information about the Digitalmars-d mailing list