[gameprogrammer] Single producer consumer

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.


--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: