Xcode ThreadSanitizer warns about SmoothedValue - can I disregard it?

Hi all,

I am doing some checks with Xcode’s ThreadSanitizer, for the first time. My own threaded code seems okay, but I am getting warnings for juce::SmoothedValue.

I have been using this class for a long time, never any problems, but after checking the source I can imagine the warnings, because writing is typically done in the message thread and reading in the audio thread. There are no atomics or locks in this class.

Can I just disregard warnings like this? I think adding mutexes / critical sections in my code around the SmoothedValue would be overkill.

This sanitizer checking is new for me.


There’s not enough information to say for sure.

The SmoothedValue doesn’t provide any threading guarantees beyond the baseline that you’d expect from any class. Calling any non-const member function of SmoothedValue simultaneously with any other member function of SmoothedValue is not safe. If you’re doing that, then the problem is in your code. Thread sanitizer will show you the call stacks that lead to a particular data race, so you should be able to work out whether you’re modifying a SmoothedValue from the main thread while reading from it on the audio thread.

If that does turn out to be the problem, then you could consider restructuring your code so that you don’t directly modify SmoothedValues from the main thread; instead, the smoothed values can check a parameter value (or similar) during the audio callback and set their state appropriately at that point.


Safety first then,

I never had issues with my typical pattern of using SV instances.
It should be very easy to silence these warnings.

Thank you!