On Fri, Mar 04, 2016 at 10:16:02AM +0100, Sebastian Gesemann wrote:
As I said, I consider JACK's ringbuffer
implementation to be broken.
According to the C11/C++11 memory model there is nothing in the code
that prevents reordering the update to write_ptr and the update to
*buf in jack_ringbuffer_write. The use of volatile only makes sure
that read/write accesses to the volatile variables are not reordered
or "optimized out" by caching. Specificaly, a volatile write is not a
release barrier. It does not constrain reordering with respect to
other memory locations (*buf). This makes the access to the buffer's
content unordered and invokes undefined behaviour.
What if writing to the buffer and updating the write pointer is
done by two separate function calls (and in that order of course) ?
The second could be inlined, but even then it's still a function call.
Ciao,
--
FA
A world of exhaustive, reliable metadata would be an utopia.
It's also a pipe-dream, founded on self-delusion, nerd hubris
and hysterically inflated market opportunities. (Cory Doctorow)