Archive for August, 2007

Carbon and thread-safety

15. August 2007

The last weeks I have spend some hours here and there to finalize the Carbon/AGL support in Equalizer.

The tricky thing is that Carbon is not thread safe for the functions Equalizer is using. The common consensus is that you should create your windows in the main thread and then fire off your (OpenGL) rendering threads.

Unfortunately I can’t do this in Equalizer, since it already has an established convention on initializing the windows in the rendering threads. Fair enough – global mutex around all window creation and destruction! Err, no, because ReceiveNextEvent is also not thread safe with the window creation calls. And of course ReceiveNextEvent wants to be called from the main thread. Ok, so also protect ReceiveNextEvent? Well, almost – you have to make sure that it doesn’t block indefinitely while holding the mutex.

So what do we end up with? The knowledge that Carbon is the least thread safe window system used by Equalizer, an event loop which polls every 50ms, a serialized window creation which has to wait up to 50ms for each window init, and an API to disable event ‘pumping’ in Equalizer.

Well, I hope the NSGL/Cocoa integration will be less hacky :-/

Advertisements