Re: [LAD] Jack midi sequencer, threading and shared state

From: Tim Goetze <tim@email-addr-hidden>
Date: Tue Aug 27 2013 - 20:50:52 EEST

[Burkhard Ritter]
>I've considered different approaches (separate data for each thread,
>various versions of shared data), but I believe all of them make at
>least two assumptions: That reading and writing byte-sized data (e.g.
>a bool flag) and that updating pointers is atomic. I got a bit
>confused reading this thread [2]. Are these assumptions correct?

It's been a while since I did some research: IIrc on i386, 32-bit read
or write access is atomic if the variable address is 32-bit aligned,
while on ARM only byte-size read and write operations are atomic,
regardless of alignment. (On a sidenote, it is not realistic to
expect gcc to honour alignment instructions.)

However, you're probably well-advised not to take my word on it. You
better research this thoroughly yourself before designing your
multithreaded architecture around it. You might go weeks before
encountering a problem, and then you might spend a week trying to hunt
it down as these things are often very difficult to recreate and
isolate, and then you might discover your basic assumptions were
wrong.

For passing data between threads locklessly in a deterministic manner,
I'd recommend a FIFO, which you can build with byte-sized counters.

Hope this helps,
Tim
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Wed Aug 28 08:15:02 2013

This archive was generated by hypermail 2.1.8 : Wed Aug 28 2013 - 08:15:02 EEST