Real time thread in Juce

Hey all,

This is a real quick question, which I know I have seen somewhere on the Juce forum before, but have not been able to find it again now.

Just to preface, I am a fairly new c++ programmer who is looking for some more juce related info on how threads are set up in the basic boiler plate plugin code.

I know that the GUI and and audio processor are run on separate threads with the audioProcessor running on a high priority thread. However, is the high-priority thread running only in the processBlock, or on any of the functions defined in the audio processor.

It is just that I am trying to develop my real-time programming practices, but I am unsure of how the threading in the AudioProcessor works. For instance, am I okay to use a lock from the GUI thread on variables that are not used within the ProcessBlock?

Any information, or just a recommendation for a good resource on the subject would be greatly appreciated!


Different hosts may call different methods on different threads, so there’s no guarentee that any given method in your plug-in’s AudioProcessor will be called on a particular thread (with the exception of processBlock which is always called on a dedicated audio thread AFAIK).

Some methods like prepareToPlay and numChannelsChanged may not be called on the audio thread but they will only ever be called when playback is stopped meaning you’re safe to alter objects that are used in your audio processing without the need for any thread-safety measures.

Easiest way to check if a method is calledon the audio thread or not is to just stick a break-point in that method and check with whatever debugger you’re using as to which thread is being used.

Even processBlock() may be called on the message thread in some cases. AFAIR Logic Pro at least does this when doing an offline bounce


wow, that’s scary

That actually sounds pretty sensible to me as it’s probably the safest way. It would mean there’s no chance of threading problems. (Although it would lead to a lot of stuttering in the UI).

This does all assume that plugins don’t do anything silly such as taking unscoped locks though…

1 Like

Thanks for all the advise! Really helpful stuff. I’ve been watching so many thread safety videos, but couldn’t apply it to how the threading was working in Juce. Setting breakpoints on the functions I’m curious about seems like a good place to start. Thanks again!

Yes, and other subtle things such as waiting for other threads (e.g., streaming from disk) and exactly how that is implemented.