[Question] "Real time safety" and inter-thread communication in Tonic.
rvega opened this issue · 4 comments
Most of the literature I've read on real-time programming for audio shows that there should be some sort of lock-free data structure (usually a ring buffer) to pass control messages from the GUI to the audio thread and another one to pass audio samples from the audio thread to the GUI (if one needs to draw the audio wave in the GUI, for example). This is to prevent audio glitches and concurrency issues.
I can see that functions like synth.setParameter() are used, but, I can't figure out if this functions implement some sort of inter-thread communication similar to the one I described or if they use mutexes or something similar instead.
Can someone please explain how the communication between GUI and audio threads work in Tonic and/or the example apps? If a lock-free data structure scheme is not used, why?
Tonic doesn't use any protection mechanism for the inter-thread
communication other than being careful not to modify anything other than
primitive values (generally floats) from anywhere but the audio thread. In
practice, this generally works fine, though is theoretically not safe.
Don't use it to launch a space ship or run power a medical device. But
generally, you can be confident that the inter-thread communication is
stable and works.
On Sat, Nov 21, 2015 at 8:27 PM, Rafael Vega notifications@github.com
wrote:
Most of the literature I've read on real-time programming for audio shows
that there should be some sort of lock-free data structure (usually a ring
buffer) to pass control messages from the GUI to the audio thread and
another one to pass audio samples from the audio thread to the GUI (if one
needs to draw the audio wave in the GUI, for example). This is to prevent
audio glitches and concurrency issues.I can see that functions like synth.setParameter() are used, but, I can't
figure out if this functions implement some sort of inter-thread
communication similar to the one I described or if they use mutexes or
something similar instead.Can someone please explain how the communication between GUI and audio
threads work in Tonic and/or the example apps? If a lock-free data
structure scheme is not used, why?—
Reply to this email directly or view it on GitHub
#270.
Morgan Packard
cell: (720) 891-0122
twitter: @morganpackard
I know this is an old thread but I also have trouble calling synth.setOutputGen()
from another thread.
I'm using imgui (a famous GUI library) and change a generator value upon moving a slider around, which is a very practical purpose of using TonicAudio and that gives me exceptions in all places. I do see that there is a MutexLock / Unlock within setOutputGen()
but that doesn't seem to help at all.
If there are any examples on best usage of the Tonic api + real-time gui I would appreciate it.
There are so many. Mostly read access violations. Running the software multiple times you will see them in different locations. Simply put, Tonic internally seem to race its own stuff. Since the only call from outside that I make is synth.setOutputGen.
Here are some of them but these are mostly coincidental. Exception Screenshots