AddPendingEvent between threads crashes on Mac

Joost imim at newhouse.nl
Fri Jun 1 18:38:34 PDT 2007


Robert Roebling wrote:
> Did you have a look at src/mac/carbon/utils.cpp, wxMacWakeUp()?
> There is a comment about a race condition there (in my version
> of that file). What version of wx are you using?

Hi Robert,

Thanks for your replies. I just took a look. I'm using 2.8.4. The part 
with the race condition comment is commented out (#if 0).

If I understand it correctly, the first alternative (which is commented 
out) checks whether a wakeupevent is already in the queue, and only 
posts it if it isn't there yet. I do understand your remark regarding 
the race condition. The second alternative simply always posts a wakeup 
event. And that second alternative is used, I don't see anything wrong 
in it.

Looking at the crash logs, to me it really looks like a clash between 
PostEventToQueue and RemoveEventFromQueue. It has happened with a user 
on a ppc machine, and I can reproduce the problem on my intel machine 
(latest OSX updates installed).

My worker thread is started whenever the user changes a parameter with a 
wxSlider, so I guess there is a relatively high chance that the thread's 
messages collide with a mouse event. I can trigger the crash when I 
continuously move the slider for some time (triggering many progress 
messages and many mouse events).

I'm thinking of an alternative solution, by creating my own message 
queue, protected by a mutex. A wxTimer in the main thread periodically 
checks for new progress messages. Ugly, but it avoids the 
PostEventToQueue completely. Any thoughts?

Thanks
Joost





More information about the wx-users mailing list