# Real time thread in Juce

**URL:** <https://forum.juce.com/t/real-time-thread-in-juce/43361>\
**Category:** Audio Plugins\
**Created:** [December 20, 2020, 3:53am UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361 "2020-12-20T03:53:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TWelby94](https://avatars.discourse-cdn.com/v4/letter/t/e47774/32.png) [@TWelby94](https://forum.juce.com/u/TWelby94)\
**Post date:** [December 20, 2020, 3:53am UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361/1 "2020-12-20T03:53:22Z")

</div>

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!

Thanks

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [December 20, 2020, 11:54am UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361/2 "2020-12-20T11:54:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [December 20, 2020, 3:52pm UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361/3 "2020-12-20T15:52:13Z")

</div>

> [@ImJimmi](#):
>
> 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).

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

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [December 20, 2020, 5:12pm UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361/4 "2020-12-20T17:12:05Z")

</div>

wow, that’s scary

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [December 20, 2020, 6:17pm UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361/5 "2020-12-20T18:17:36Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![TWelby94](https://avatars.discourse-cdn.com/v4/letter/t/e47774/32.png) [@TWelby94](https://forum.juce.com/u/TWelby94)\
**Post date:** [December 20, 2020, 10:39pm UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361/6 "2020-12-20T22:39:54Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [December 21, 2020, 1:06pm UTC](https://forum.juce.com/t/real-time-thread-in-juce/43361/7 "2020-12-21T13:06:15Z")

</div>

> [@dave96](#):
>
> This does all assume that plugins don’t do anything silly such as taking unscoped locks though…

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