|
On 17/03/2012 7:11 PM, Gaspard Bucher wrote:
[1]
https://github.com/lubyk/lubyk/blob/master/modules/lk/include/lubyk/Fifo.h
With the exception of Visual C++2005 (and maybe later) where "volatile" also implies implicit memory barriers, the above linked code is not guaranteed to be safe.
Atomicity of the read and write pointers is not sufficient.
It is necessary to add processor memory barriers to ensure that the written data in the queue buffer is visible to the reader at the point that the reader sees the write pointer change.
Required memory barriers and barrier pairing will depend on the architecture.
Ross.
1. Write data in fifo: data_[write_idx_] = data;2. Notify pipe: write(pipe_fd_[1], "", 1);
3. Lua 'select' returns... yield the coroutine... and pop: T *data = data_[read_idx_];
if(data_[write_idx_] == data)write(pipe_fd_[1], "", 1);