Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #583
| From | Alexander Terekhov <terekhov@web.de> |
|---|---|
| Newsgroups | comp.programming.threads |
| Subject | Re: usage of vyukov's mpsc queue |
| Date | 2011-09-21 12:34 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <4E79BDBA.D6ED6F8D@web.de> (permalink) |
| References | <3b312755-24d8-4505-8cfe-1644c458c4d5@j1g2000yqn.googlegroups.com> <4E79BA45.B3622870@web.de> |
Alexander Terekhov wrote:
>
> Ephi Sinowitz wrote:
> >
> > Hi,
> > I implemented the queue http://www.1024cores.net/home/lock-free-algorithms/queues/intrusive-m...
> > with a signaling mechanism for the consumer.
> > Do I need to ensure visibility somehow before setting the event since
> > I'm not spinning in the consumer? How?
> > Producers:
> > ----------------
> > vyukov_queue.push(item);
> > SetEvent(m_queueEvent);
> > Consumer:
> > ---------------
> > for(;;)
> > {
> > WaitForSingleObject(m_queueEvent, INFINITE);
> > while (void* item = vyukov_queue.pop())
> > {
> > // do work
> > }
> > }
> > For reference here is the push()
> > void MPSC_Queue::push(void* item)
> > {
> > item->next = NULL;
> > void* old_head = InterlockedExchangePointer((void *volatile
> > *)&m_head, item);
> > // BLOCK POINT
> > old_head->next = item; // Do I need to ensure this is visible to
> > the consumer thread?
> > }
>
> Yes, you need to make old_head->next = item store atomic-release store.
>
> Consumer's m_tail->next load must be atomic-acquire load.
>
> Producer's RMW can be totally relaxed with respect to memory barriers.
Producer's RMW can be totally relaxed with respect to memory barriers if
implemented as load-reserve/store-conditional or CAS loop (making
subsequent stores control-dependent).
OTOH, for loopless XCHG-style RMW you need to ensure that it has acquire
semantics (InterlockedExchangePointerAcquire in MS terms).
regards,
alexander.
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
usage of vyukov's mpsc queue Ephi Sinowitz <esinowitz.public@gmail.com> - 2011-09-20 06:55 -0700
Re: usage of vyukov's mpsc queue Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-20 17:19 -0700
Re: usage of vyukov's mpsc queue Ephi Sinowitz <esinowitz.public@gmail.com> - 2011-09-20 18:35 -0700
Re: usage of vyukov's mpsc queue Ephraim Sinowitz <ephisinowitz@yahoo.com> - 2011-09-21 06:42 -0400
Re: usage of vyukov's mpsc queue Joshua Maurice <joshuamaurice@gmail.com> - 2011-09-21 00:26 -0700
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-09-21 12:19 +0200
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-09-21 12:34 +0200
Re: usage of vyukov's mpsc queue Ephi Sinowitz <ephisinowitz@yahoo.com> - 2011-09-21 06:58 -0400
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-09-21 14:02 +0200
Re: usage of vyukov's mpsc queue Ephi Sinowitz <esinowitz.public@gmail.com> - 2011-09-21 06:08 -0700
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-09-21 15:18 +0200
Re: usage of vyukov's mpsc queue Ephi Sinowitz <esinowitz.public@gmail.com> - 2011-09-21 06:56 -0700
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-09-21 17:06 +0200
Re: usage of vyukov's mpsc queue Ephi Sinowitz <esinowitz.public@gmail.com> - 2011-09-21 09:16 -0700
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-09-21 18:20 +0200
Re: usage of vyukov's mpsc queue Dmitriy Vyukov <dvyukov@gmail.com> - 2011-09-21 09:58 -0700
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-09-21 19:33 +0200
Re: usage of vyukov's mpsc queue dvyukov@google.com - 2011-10-02 04:13 -0700
Re: usage of vyukov's mpsc queue Alexander Terekhov <terekhov@web.de> - 2011-10-04 12:15 +0200
Re: usage of vyukov's mpsc queue Ephi Sinowitz <esinowitz.public@gmail.com> - 2011-09-21 11:04 -0700
Re: usage of vyukov's mpsc queue Ephi Sinowitz <esinowitz.public@gmail.com> - 2011-09-21 11:17 -0700
Re: usage of vyukov's mpsc queue "Chris M. Thomasson" <cristom@charter.net> - 2011-09-24 22:44 -0700
csiph-web