MidiMessageSequence list thread safety

Shouldn’t the list OwnedArray use a CriticalSection – or should you template the MidiMessageSequence class to allow us to set if the OwnedArray is thread safe?



I assume you’re going between the audio and message threads? Avoid locks! That’s why the swapWith method exists - lock for an extremely short and predictable amount of time to quickly swap two copies of the MidiMessageSequence any time the model changes in the message thread. I just coded something like this and it works great. Several audio-centric JUCE structures which allow modify options under the hood (notably AudioProcessorGraph) also use this method.

Unless you’re doing something new and crazy?

I actually do that – but have run into an issue about 1% of the time when doing this under Windows (even less under MacOS).

I should point out that the issue I have isn’t between the audio thread and the message thread - I have a worker thread which updates the sequence.