Naive question about Juce thread safety


#1

If I am updating a float value in the message thread (slider callback), and I use this in the processBlock() on the Audio thread, surely I need to make the float Atomic? I understand I can access the slider value directly in the processBlock() as per the ‘control audio levels’ tutorial (which I assume is thread safe) but this is just a basic example.


#2

i’ve seen a good post here

"The reason they’re done the way they are in the samples is to make the code more readable for beginners. From what I understand it’s technically alright for intel platforms because 32-bit reads/writes are always atomic, so in almost all cases it’s “safe enough” for example code.

How you decide to make them satisfiably thread safe is up to you - there has been debate recently on the best way to achieve inter-thread communication of parameters including double buffering with an intermediate audio processing thread, wrapping parameters in lock-free atomics, or just ignoring the issue for Intel platforms. Someone else with more plugin experience can probably give a better/more definitive answer for real-world practices."

Which answers my question enough for me.