# Check if on audio thread

**URL:** <https://forum.juce.com/t/check-if-on-audio-thread/30823>\
**Category:** Development\
**Created:** [December 11, 2018, 5:09pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823 "2018-12-11T17:09:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrushedPixel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/crushedpixel/32/8654_2.png) [@CrushedPixel](https://forum.juce.com/u/CrushedPixel)\
**Post date:** [December 11, 2018, 5:09pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/1 "2018-12-11T17:09:43Z")

</div>

Is there a simple call to check if we’re on the audio thread?  
I’d like to use it for some `jassert`s to avoid developer stupidity.

What I’m using to check if we’re currently on the message thread:  
`jassert(juce::MessageManager::getInstance()->isThisTheMessageThread());`

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [December 11, 2018, 5:35pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/2 "2018-12-11T17:35:31Z")

</div>

```
jassert(!juce::MessageManager::getInstance()->isThisTheMessageThread());

```

Doing anything more fancy is going to be complicated. There might not necessarily be just _one_ audio thread due to the host’s multithreading. There’s no reason to assume the host will be calling the same plugin’s audio processing always from the same thread. (For example Reaper uses a multithreading model where whatever worker thread happens to have the chance to process the track and its plugins, gets to do the work.)

---

<div class="post-metadata">

**Author:** ![CrushedPixel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/crushedpixel/32/8654_2.png) [@CrushedPixel](https://forum.juce.com/u/CrushedPixel)\
**Post date:** [December 11, 2018, 5:47pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/3 "2018-12-11T17:47:14Z")

</div>

Thanks, that makes sense. It’s just an assertion to make sure I don’t accidentally screw up coding anyway, so it’s perfectly fine for my use case.

---

<div class="post-metadata">

**Author:** ![CrushedPixel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/crushedpixel/32/8654_2.png) [@CrushedPixel](https://forum.juce.com/u/CrushedPixel)\
**Post date:** [December 12, 2018, 3:43pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/4 "2018-12-12T15:43:35Z")

</div>

> [@Xenakios](#):
>
> jassert(!juce::MessageManager::getInstance()-\>isThisTheMessageThread());

I have to report that this line sometimes falsely asserts, even when being called directly from `processBlock`. I’m on Logic Pro X.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 12, 2018, 3:56pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/5 "2018-12-12T15:56:10Z")

</div>

The `isThisTheMessageThread()` is usually used, because many operations on the message thread are not designed to be thread safe. The intention is, to make sure some operations, that access data, that the message thread accesses as well, cannot come from another thread.

Maybe the opposite assumption is not always true. I don’t know, if the host is not allowed to call processBlock from the message thread? (Maybe to flush parameters or whatever…)

Logic does surprising things sometimes…

---

<div class="post-metadata">

**Author:** ![CrushedPixel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/crushedpixel/32/8654_2.png) [@CrushedPixel](https://forum.juce.com/u/CrushedPixel)\
**Post date:** [December 12, 2018, 4:07pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/6 "2018-12-12T16:07:54Z")

</div>

Yeah, I came to the same conclusion.  
Just wanted to share it here to make people aware that this does not seem to be a catch-all solution 🙂

---

<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 12, 2018, 5:32pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/7 "2018-12-12T17:32:51Z")

</div>

I think in non realtime mode some hosts use the message thread for processBlock(). It’s feasible anyway.

---

<div class="post-metadata">

**Author:** ![yfede](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/yfede/32/506_2.png) [@yfede](https://forum.juce.com/u/yfede)\
**Post date:** [December 13, 2018, 4:37pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/8 "2018-12-13T16:37:05Z")

</div>

You may check this other topic: [Class for detecting unsafe operations in realtime contexts](https://forum.juce.com/t/class-for-detecting-unsafe-operations-in-realtime-contexts/26330)

---

<div class="post-metadata">

**Author:** ![guimaraesluis](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@guimaraesluis](https://forum.juce.com/u/guimaraesluis)\
**Post date:** [May 3, 2026, 4:09pm UTC](https://forum.juce.com/t/check-if-on-audio-thread/30823/9 "2026-05-03T16:09:59Z")

</div>

Just wanted to share that currently `isThisTheMessageThread` locks, so it can’t be called on the audio thread. There was some discussion about this here: [Make isThisTheMessageThread() lock free](https://forum.juce.com/t/make-isthisthemessagethread-lock-free/62620)
