Thread communication in advanced tutorial on looping audio

I am looking at the tutorial on Looping Audio using AudioSampleBuffer class (advanced)

The path of the file to open is passed from the MessageThread - openButtonClicked() - to the background thread - checkForPathToOpen() - using a simple swap on the file path of type String.

Having looked at the code, juce::String::swapWith() resolves to a std::swap on the char pointers that point to the allocated memory for the string. While definitely very fast, the swap on char* is still implemented with three move instructions (using Visual Studio 2017).

Therefore, it seems to me that this solution is not technically thread safe, and would rather require a CriticalSection.

Or am I missing something here ?


Hi, I just finished this tutorial and had the exact same question! Did you figure out the answer?

Thanks for reporting this issue. I’ve updated the tutorial to improve its thread safety, and this new version should be made public in a week or so.

1 Like