[linux-audio-dev] lock-free ring buffer code

Paul Davis paul at linuxaudiosystems.com
Fri Apr 4 07:53:15 UTC 2003

>below is what i use (i think it works). the primary thing to notice
>is that readers and writers are kept in line by the atomicity of
>integer assignment (though in general, we should probably declare them
>atomic_t or something).

just for completeness sake, this isn't really true. the atomicness of
int writes/reads isn't central. what is central is (as you noted) the
single (group of synchronous) reader(s) and single (group of
synchronous) writer(s), and the monotonic motion of the read+write

otoh, i suppose if it was possible to read an int half-way through the
write and get a value randomly related to the one it was actually
being set to, that might be a problem.

there is one aspect of the LFRB that bothers me. as has been explained
many times, the monotonic motion of the read/write pointers is
key. but when one the reader/writer moves the pointer to the end of
the buffer and wraps it around, that operation does not cause
monotonic motion (its semantically monotonic, but in fact the pointer
value goes from high to low). i've never quite satisfied myself that
this is threadsafe.

More information about the Linux-audio-dev mailing list