[linux-audio-dev] Locks or no locks?

nick thomas jesuswaffle at gmail.com
Fri Jan 12 06:45:54 UTC 2007

I apologize if this has been discussed previously on the list; Google
didn't seem to be turning anything up from the list archives.

I'm writing my first DSP program for JACK. My problem is this: I've
got a high-priority audio synthesis thread, and a low-priority user
interface thread, and they need to communicate: the UI thread needs to
tell the synthesis thread to respond to the user twisting knobs and
moving sliders in the interface, and the the synthesis thread needs to
tell the UI thread what it's doing, so that the UI thread can update
its monitoring widgets. I'm sure that this is an extremely common
situation for JACK programs, and I was wondering how to handle it.

I know of two possible approaches: using locks and shared memory, or
using FIFOs and no shared memory. Vanilla pthreads provides direct
support for the former approach, and JACK's ringbuffer interface seems
to provide the necessary primitives to implement the latter approach.

A lock-based system would probably be substantially simpler to
implement than a lock-free one; however, I can imagine some possible
priority inversion issues with a lock-based system. I don't know if
that is ever a problem in practice, with real-time scheduling enabled.

Anyway, there's my question: which approach (lock-based or lock-free)
is generally favored for JACK programs? Thanks for helping a newbie

More information about the Linux-audio-dev mailing list