Thread communication in advanced tutorial on looping audio


#1

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 ?