On Sep 21, 11:06 am, Ephi Sinowitz <
esinowitz.pub...@gmail.com> wrote:
> But I am on x64. Shouldn't the STORE-RELEASE /LOAD-ACQUIRE come
> automatically.
http://www.justsoftwaresolutions.co.uk/threading/intel-memory-orderin...
>
> > However, that frequent signaling makes the whole algorithm sort of
> > senseless, because SetEvent is heavy and most likely involved locking.
> > Ideally you want to signal only when there is a waiting consumer.
> > Simple CRITICAL_SECTION+CondVar will be most likely faster than this.
>
> OK. So like this?
> Producers
> ---------------
> push()
> if (TryEnterCriticalSection(&cs)) WakeConditionVariable(&cond);
> Consumer
> ---------------
> EnterCriticalSection(&cs);
> for (;;)
> SleepConditionVariableCS (&cond, &cs, INFINITE);
> while (void* item = vyukov_queue.pop())
> {
> // do work
> }
Good try, but condvars do not work that way.
Consider the following sequence of events:
1. Consumer checks that the queue is empty.
2. Producer puts an element into the queue.
3. Producer tries to lock the mutex and fails.
4. Consumer unlocks the mutex and blocks forever while there is the
element in the queue.
Search this group, or c.p.t, or Intel Software Network for
"eventcount". Perhaps Intel Software Network is the best place to
start, search for "eventcount gate" there.