[gameprogrammer] Re: Single producer consumer
- From: Bob Pendleton <bob@xxxxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Thu, 09 Feb 2006 12:58:35 -0600
On Thu, 2006-02-09 at 09:21 -0800, Kevin Jenkins wrote:
> We're having a debate at work right now as to if you can write a
> thread-safe single producer consumer class without critical section
> locks. I claim you can, while another programmer claims you cannot.
> This is what I use:
>
> http://www.rakkar.org/sourcecode/SingleProducerConsumer.h.txt
>
> What I do is have two pointers - a write pointer and a read pointer.
> They cannot cross each other. Each pointer is only modified by one
> thread. Both threads compare these pointers using the == operator.
>
> There are a few articles on google claiming correctly you cannot use a
> single shared pointer or index where both threads modify that variable,
> but none use my approach where I have two variables and each is only
> updated by its own thread.
I have used that technique in production code and it works great.
Better, it is provably correct. People get worried about the possibility
of comparing partially updated pointers. But, if you look at the range
of possible values for the pointers and the values that can be generated
by examining a partially updated multibyte pointer you see that this is
not a problem.
Bob Pendleton
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
--
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: Bob@xxxxxxxxxxxxx +
+ web: www.GameProgrammer.com +
+ www.Wise2Food.com +
+ nutrient info on 7,000+ common foods +
+--------------------------------------+
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: Single producer consumer
- From: Kevin Jenkins
- References:
- [gameprogrammer] How to have hills in a tiled game
- From: Alan Wolfe
- [gameprogrammer] Single producer consumer
- From: Kevin Jenkins
Other related posts:
- » [gameprogrammer] Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- » [gameprogrammer] Re: Single producer consumer
- [gameprogrammer] Re: Single producer consumer
- From: Kevin Jenkins
- [gameprogrammer] How to have hills in a tiled game
- From: Alan Wolfe
- [gameprogrammer] Single producer consumer
- From: Kevin Jenkins