Threading Issues

Hi,

I’m in the process of writing a Studio Connections plug-in and have come across an awkward situation.

My plug-in is a client to a server program, and the two communicate using XML. The client program has a separate thread that’s used to listen for incoming XML documents from the server. Some of the XML documents that come from the server instruct the client application to make changes to its UI. The UI is updated with the aid of an AsyncUpdater.

When Cubase starts up my plug-in, Cubase initially tells my plug-in to initialize itself, then immediately after tells it to load it self up from a persist stream.

When my plug-in initializes itself, it sends a request to the server asking for its current configuration and the server takes its own time to respond with the current configuration. But, the problem is that my plug-in can only load itself from the persist stream once it’s aware of the current configuration, but it gets told to load itself from the persist stream before the configuration response comes back from the server.

Now, I thought of using a WaitableEvent: When I send out a request to the server, the client application calls wait(), and when the response is returned from the server and the client application has been updated I call signal(). Cubase can then continue to request the plug-in the load itself. But, as I’m using the AsynUpdater to update my UI, and the message loop is locked (as I called wait()), the handleAsynUpdate() method does not get called as the message loop is waiting for it to get signaled.

My second attempt involved me trying to update the UI from the server thread directly, but, as it’s not thread safe to update UI components from a thread other than the message thread, I have to lock the MessageManager. But trying to lock the MessageManager from the server thread causes my program to hang – I’ve seen other people have had a similar problem.

So, my question is, how do I get my program to wait for a response from the server, and make it so that it’s possible to safely update my UI?

Philip

Probably best to just stick all the processing in the other thread - so when you get the persistent state block, just copy it somewhere and the thread can restore from it when it’s ready?

Ah, let me give that a bash! It’s not quite ideal, but I think that it’ll do in this situation. Thanks!

Yip, did the trick! Thanks for the advice!