Re: [LAD] a *simple* ring buffer, comments pls?

From: Gabriel M. Beddingfield <gabrbedd@email-addr-hidden>
Date: Fri Jul 08 2011 - 21:12:08 EEST

On Friday, July 08, 2011 12:17:34 pm Fons Adriaensen wrote:
> On Fri, Jul 08, 2011 at 09:21:55AM -0400, Paul Davis
wrote:
> > the one wrinkle in this is that in theory a compiler
> > could so completely reorder instructions that even the
> > basic assumptions that make the single
> > reader/single-writer ringbuffer safe would break down.
>
> AFAIK nothing fatal can happen if the variables involved
> are declared volatile. A compiler is not allowed to
> omit, repeat, or re-order instructions involving them.

Take for instance jack_ringbuffer_read(), which has this
line:

  rb->read_ptr = (rb->read_ptr + n) & rb->size_mask;

There's a remote possibility that the compiler could
optimize this as:

  rb->read_ptr += n;
  rb->read_ptr &= rb->size_mask;

...and this would break the ringbuffer. I don't know if the
`volatile` keyword prevents this or not.

-gabriel
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Sat Jul 9 00:15:01 2011

This archive was generated by hypermail 2.1.8 : Sat Jul 09 2011 - 00:15:01 EEST