# Help with callFunctionOnMessageThread

**URL:** <https://forum.juce.com/t/help-with-callfunctiononmessagethread/12908>\
**Category:** General JUCE discussion\
**Created:** [May 27, 2014, 1:51pm UTC](https://forum.juce.com/t/help-with-callfunctiononmessagethread/12908 "2014-05-27T13:51:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![w\_ellis](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/w_ellis/32/176_2.png) [@w\_ellis](https://forum.juce.com/u/w_ellis)\
**Post date:** [May 27, 2014, 1:51pm UTC](https://forum.juce.com/t/help-with-callfunctiononmessagethread/12908/1 "2014-05-27T13:51:58Z")

</div>

Hi all,

Apologies in advance if this is a bit of a noob question, but I'm not yet too proficient in the subtleties of C++, so function pointers are a new topic for me.

I'm trying to set up a callback from the&nbsp;callFunctionOnMessageThread method in order that I can process GUI events (hiding and showing a window) from a real-time thread.

What I have so far (super simplified), looks a bit like this:

```
class MyClass
{
private:

void* showMyWindow(void*);
void ProcessStuffOnRealtimeThread();

ScopedPointer<DocumentWindow> myWindow;
}

void* MyClass::showMyWindow(void*)
{
myWindow = new DocumentWindow();
}

void MyClass::ProcessStuffOnRealtimeThread()
{
MessageManager* mm = MessageManager::getInstance();
mm->callFunctionOnMessageThread(MyClass::showMyWindow, nullptr);
}
```

Again, please don't laugh&nbsp;too hard at me :)

Thanks in advance,  
Will

P.S. I read and re-read the documentation, plus all the material on function pointers that I could find and then just tried everything I could think of...

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 27, 2014, 2:10pm UTC](https://forum.juce.com/t/help-with-callfunctiononmessagethread/12908/2 "2014-05-27T14:10:12Z")

</div>

Agh! No no no no...

You probably _never_ want to call&nbsp;callFunctionOnMessageThread() - it has serious potential to deadlock. But even if it didn't, calling it on your real-time thread is probably&nbsp;the worst&nbsp;place you could possibly&nbsp;use it!&nbsp;It _blocks_ until the function has returned, so it'll block your audio thread. (And possibly deadlock it too)

Just get yourself a shared atomic&nbsp;variable, write it in your audio thread, and use a timer or something in your UI thread to check it for changes.

---

<div class="post-metadata">

**Author:** ![w\_ellis](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/w_ellis/32/176_2.png) [@w\_ellis](https://forum.juce.com/u/w_ellis)\
**Post date:** [May 27, 2014, 4:05pm UTC](https://forum.juce.com/t/help-with-callfunctiononmessagethread/12908/3 "2014-05-27T16:05:26Z")

</div>

Hi Jules,

Thanks so much for the quick response! The reason I was considering it was a) my real-time thread is actually handling controller messages, rather than audio, so it's not quite&nbsp;as critical and b) I'm not controlling the UI thread (I'm building a module that plugs into a 3rd party's application).

However, creating a timer callback is a much simpler solution anyway and will work fine for my needs, so I'll go with that. Thanks for the help!

Cheers,  
Will
