I need some advice about what kind of IPC and what kind of message queue types might be the best kind to use for my specific circumstances (producers/consumers, priority & timing etc).
I'm working on a realtime audio/graphics app in C for Linux (Ubuntu) which uses OpenGL and SDL graphics, ALSA audio (MIDI), POSIX pthreads, and custom libraries for peripheral hardware. Currently there is a main thread and a thread for communication with the peripheral devices. The main thread combines the main graphics draw cycle with the code which controls the recording/playback of audio (or more correctly, MIDI events set up for looped recording/playback).
I need to separate the audio into its own thread as the main thread is not currently strictly timed (i.e. the main draw cycle does not always take the same amount of time to finish an iteration, depending on what's being drawn from one iteration to the next) and this is preventing the 'playback' of audio loops (firing of MIDI events) from being constant in timing.
The audio thread needs to be strictly timed so that recording/playback is consistent, and it needs to receive trigger events from the peripheral-handler thread (and note there may be more than one peripheral thread producing events), but not wait for them long enough that the playback timing is interfered with at all. The trigger events sent by the peripheral thread(s) need to be synchronized with the audio thread so that when a user triggers the playing/recording of a note, it plays at the right time (i.e. immediately, when playing a note, or recorded into the correct position in the recording loop).
The audio thread sends 'draw' events to the graphics thread (which I guess will remain the main program thread) and the graphics thread should draw them as soon as possible, so that the graphics events appear synchronized with the audio playback events - though the graphics thread does not have to be as strictly timed as the audio thread.
I hope that's clear enough for people to be able to suggest what I should try out. I'm not too familiar with queue algorithms, blocking, locks and mutexes etc, but I understand the basic concepts, so if anyone can suggest which kind of queue or messaging algorithms I should look at, and link to any examples/implementations in C, that would be great. Many thanks!