Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Alexander Terekhov Newsgroups: comp.programming.threads Subject: Re: usage of vyukov's mpsc queue Date: Wed, 21 Sep 2011 18:20:13 +0200 Organization: A noiseless patient Spider Lines: 39 Message-ID: <4E7A0EBD.EF170AC8@web.de> References: <3b312755-24d8-4505-8cfe-1644c458c4d5@j1g2000yqn.googlegroups.com> <4E79BA45.B3622870@web.de> <2011092106580817537-ephisinowitz@yahoocom> <4E79D246.E338E050@web.de> <39ca082e-34ad-43f5-8f6d-9944ae840875@l4g2000vbv.googlegroups.com> <4E79E431.59EFC897@web.de> <7f52d142-c0f4-4898-a498-2cf78fb4f97e@k15g2000yqd.googlegroups.com> <4E79FD7A.F4557F50@web.de> <94ee4bc5-9502-4b0c-9b45-46e5f5ef8f9f@l2g2000vbn.googlegroups.com> Reply-To: terekhov@web.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="MCbSEzW5qwGLFMNXJh39IQ"; logging-data="22952"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MmwI8G0QGE+K+B4n3ERMgxmitHg5+MU0=" X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en Cancel-Lock: sha1:1EeIxlIAlMq6CxDeUNkJH7/Iuas= Xref: x330-a1.tempe.blueboxinc.net comp.programming.threads:592 Ephi Sinowitz wrote: > > On Sep 21, 11:06 am, Alexander Terekhov wrote: > > Ephi Sinowitz wrote: > > > > [...] > > > > > Producers set event after the push(). Event only transitions from > > > unset to set when producer is inside the while loop. > > > Now when Consumer goes back to Wait he should see the set event. The > > > only issue is that he may still see a NULL next pointer because there > > > are no memory barriers in the push(). In that case the consumer will > > > go back to wait and the event will stay unset forever. But the 30 > > > second time limit should take care of that. > > > for(;;) > > > WaitForSingleObject(m_queueEvent, 30000); > > > while (void* item = vyukov_queue.pop()) > > > { > > > // do work > > > } > > > } > > > > With *timed* wait on in consumer, push() and pop() need the > > same barriers as without blocking synchronization object. > > > > Think of it as sleep(30) instead of WaitForSingleObject(m_queueEvent, > > 30000). > > > > regards, > > alexander. > > But that's the point. This queue does not need any memory barriers if > the consumer is just spinning with a sleep. Who told you that, Ephi? regards, alexander.