Message Thread and Audio Thread stuck waiting for eachother

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:

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:

Meanwhile, the “JUCE WASAPI” thread is stuck in my parameterChanged method:

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!

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.