Thread and Graphics


I’m using Juce for a project.
There is a thread into I receive information. According to this information I must change some graphics stuff.

Until now, I used MessageManagerLock but in the case of a window name change the program blocks in a subfunction of setName.

simplified example code:

in a subfunction of run thread method

MessageManagerLock mml (Thread::getCurrentThread());

if (! mml.lockWasGained())
  return; // another thread is trying to kill us!


When I comment the MessageManagerLock I have two jassert
(juce_component.cpp l183 and l1633) but all is OK. And I know it’s not threadsafe…

So is there a bug?

thank you for your answers

(excuse me for my English, I’m French! :lol: )

I don’t think there’s a bug, but like it says in the docs, you need to be very careful when using the MessageManager because it’s easy to deadlock - e.g:

  • your normal message thread wants to stop your other thread, so it calls stopthread and waits for it to stop.

  • then, your other thread hits an MM lock section and sits there waiting for the lock (which is held by the main message thread), so can never stop, and the whole thing deadlocks.


I use a MessageListener to call all my graphics methodes… So the MessageManager do all with the main thread and Now all is fine… (and faster!)