What sync object should i use?

Dmitry Olshansky dmitry.olsh at gmail.com
Tue May 14 01:58:27 PDT 2013


14-May-2013 08:33, Heinz пишет:
>> BTW, given recent discussion on memory barriers, I think my previous
>> statement that the mutex does not need to be locked to call notify is
>> probably incorrect.
>

Have to lock it otherwise you have a race condition on a condition 
variable (wow!).

> Haven't had any issues calling notify outside a synchronized statement,
> even from multiple threads. At least this works under Win32 with my
> producer thread all wrapped inside synchronized(). Only a single
> consumer thread is inside synchronized() but then i have 2 more threads
> making naked calls to notify(). Not a single crash.

Doesn't prove anything, it could happen that you just miss a 
notification, for instance. Another common case is that it so happens 
that wait will (with luck) always happen before any of notify and 
notifications come spaced out in time.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list