[gameprogrammer] Re: Single producer consumer


In other words, I was wrong. You need an atomic read/write to make this
work.


I have used this in production code, but the counters were 1 byte values
(68000 assembly code) and I am pretty sure that 1 byte read/writes are
atomic on all systems I have every seen. And, 1 byte counters can make a
very nice queue that is big enough for most applications.


My apologies to the group for posting false information,

I think that writes and reads are atomic on single processor systems. I updated my single producer consumer to work even for non-atomic reads and writes.


http://www.rakkar.org/sourcecode/SingleProducerConsumer.h.txt

As I said in the last email, it writes a volatile bool before updating the read or write pointer. The read or write will fail if either respective value is incorrect, or either value correctly indicates that it should fail. Since the pointer and bool writes are atomic, they happen in-order, and thus the code should work.


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


Other related posts: