Page 1 of 1

Thread communication between ProcessSample/UI

Posted: Tue Jun 30, 2020 1:12 pm
by arbuxMusic
The UI update and SampleProcess calls are documented as performing on different threads. However, the sample modules in the developer kit don't provide any explicit synchronisation of variables for inter-thread communication.

On the one hand, that's great for performance. On the other hand, presumably it may lead to concurrency issues (particularly given that double/long are guaranteed to be updated atomically).

For example, if I want to display a near-realtime waveform buffer screen update based on sample input, is there any recommended good practice on how to write to the buffer (ProcessSample without blocking) and read the waveform (from the UI thread every N milliseconds - hence the need for a buffer rather than a single value)? The closest I could see was the Oscilloscope demo module, but that code doesn't explicitly synchronise the values between the threads (aka make sure that the buffer is guaranteed to be written to memory prior to the Gui thread picking it up).

... or is it that I am missing something fundamental in the Modules architecture? :D