# Message Thread and Audio Thread stuck waiting for eachother

**URL:** <https://forum.juce.com/t/message-thread-and-audio-thread-stuck-waiting-for-eachother/32755>\
**Category:** General JUCE discussion\
**Created:** [April 8, 2019, 3:15pm UTC](https://forum.juce.com/t/message-thread-and-audio-thread-stuck-waiting-for-eachother/32755 "2019-04-08T15:15:45Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [April 8, 2019, 3:15pm UTC](https://forum.juce.com/t/message-thread-and-audio-thread-stuck-waiting-for-eachother/32755/1 "2019-04-08T15:15:45Z")

</div>

I have an issue with a plugin where it seems the Message Thread and Audio (WASAPI) Thread are both stuck waiting for eachother while trying to aquire locks.

This happens when using a `MessageManagerLock` object in `parameterChanged` as it seems the Message Thread is trying to aquire a lock to be able to call the `parameterChanged` callback, but it can’t because at the same time one of my `parameterChanged` methods is trying to aquire a lock to call `repaint` on a component.

99% of the time, the locks are aquired fine, however, 1% of the time the plugin freezes (but doesn’t crash or hit a breakpoint). When I hit pause in VS and look at the threads I see this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/794ea53208848ef1ede6ecee45f63adaa3f3ab03.png)  
If I hit continue and wait a few seconds before hitting pause again, all the theads are in the exact same place.

Going up the Call Stack on each of the threads shows that the “JUCE Message Thread” is stuck in `AudioProcessorParameter::sendValueChangeMessageToListeners`:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/6/609cf76fa0286c854e447eb7caa935191cce3e43.png)

Meanwhile, the “JUCE WASAPI” thread is stuck in my `parameterChanged` method:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/8/883e54f2dc22c85ac8234eb3eafc678d5dd95adf.png)

This also happens in another `parameterChanged` method in a different class that is using `MessageManagerLock` in the same way.

As I said, 99% of the time when the parameter is updated there’s no issue at all and the UI updates as it should but eventually it always ends up in the frozen state.

If anyone can help out at all I would be massively grateful!

---

<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:** [April 8, 2019, 3:39pm UTC](https://forum.juce.com/t/message-thread-and-audio-thread-stuck-waiting-for-eachother/32755/2 "2019-04-08T15:39:28Z")

</div>

After looking at the `SliderAttachment` class in `AudioProcessorValueTreeState` I’ve now implemented the same structure by using `AsyncUpdater` and moving the code in `parameterChanged` to `handleAsyncUpdate` and calling `triggerAsyncUpdate` in `parameterChanged`.

Seems to be working so far, I will report back if it still continues to freeze.
