Locks in ProcessBlock in non-realtime processing

I have a plugin where there are some calculations which occur on the Message thread as a result of parameter changes. Their results are used in the audio thread (all safely through atomics).

In my prepareToPlay(), I check whether isNonRealtime() and set the result to an atomic bool. In my processBlock() and parameterChanged() methods I check the value of this flag and if it is true I acquire a lock.

Is this best practice? If not, what should I look to do?

Blocking in offline rendering should be alright, you could probably just check isNonRealtime() directly inside the method if you have a hook to it.

Is there a reason to use the message thread? Simply to keep the CPU lower on the processing thread? It will block the UI and make the frontend feel laggy if it’s too long, you could consider spinning up another thread specifically for these calcs

1 Like

Thanks for the advice.

Got it. I didn’t notice that it just returns the value.

Not a particularly good reason. We haven’t found the UI laggy at all in testing, but if that becomes an issue I bet a new thread would be a good call.