[LAU] Simple, easy multithreaded circular buffer library for Linux?

Ken Restivo ken at restivo.org
Tue Oct 14 15:56:31 EDT 2008


On Tue, Oct 14, 2008 at 09:21:07AM +0200, Leslie P. Polzer wrote:
> 
> > I'm being lazy, so instead of researching everything that's out there, I'll ask here:
> > can anyone recommend a relatively simple and painless abstraction library (GPL or LGPL
> > of course) that will give me functions to create a thread in which I can stuff things
> > into a ring buffer, and another thread in which I can pull stuff out of it?
> 


Thanks for all the replies!

The JACK buffer seems very nice, and probably the fastest and simplest approach (though, not the most abstracted). By not requiring locks, that'd make dealing with pthreads much simpler-- just create and then join the threads, no need to deal with mutexes, etc.

The data I'm buffering are ALSA MIDI snd_seq_event_t pointers. I'm using C because this is a simple little daemon, and I am a latency freak and I wanted speed. If I were using Python (or some other high-level language) then the threading and buffering would be ridiculously simple, of course.

After researching it a bit, it seems that the simplest way with the simplest code would be to use an "asynchronous queue", as it's called in Glib. Just cast the pointer to void, attach it to a message, and push it onto a queue. In the consumer thread, just push it off of the queue and cast it to snd_seq_event_t * again.

Glib is very easy to use, but the JACK/pthreads approach seems lighter weight so I might try that first.

Thanks again!

-ken



More information about the Linux-audio-user mailing list