AddPendingEvent between threads crashes on Mac

Robert Roebling robert at roebling.de
Fri Jun 1 03:43:14 PDT 2007


Joost wrote:

> I have a worker thread that reports it progress a dialog box. It
> does by posting an event:
> 
> void MyThread::SendProgress(int progress)
> {
>    wxCommandEvent event(myEVT_PROGRESS);
>    event.SetInt(progress);
>    m_Dialog->AddPendingEvent(event);
> }

That is how it should be done.

> On the mac this causes an occasional crash. Below are the relevant parts 
> of the crash report. If I read it correctly, the main thread was 
> processing my mouse movements, doing a RemoveEventFromQueue. The worker 
> thread was just at the same time doing a PostEventToQueue to that same 
> queue.

PostEventToQueue is supposed to be used for this and it is
thread-safe.

> So.. is this actually a thread synchronization bug in OSX ?!

Hm, somehow hard to believe. No idea.

> 
> Thanks
> Joost
> 
> 
> 
> Thread 0 Crashed:
> 0   RemoveEventFromQueue + 125
> 1   _TrackMouseLocationReturningEvent + 565
> 2   TrackMouseLocationWithOptions + 87
> 3   HIView::TrackMouseLocation(double, Point, Point&, unsigned long*, 
> unsigned char&, void*&) + 129
> 4   HIView::DragLiveIndicator(CGPoint const&, unsigned long*, void 
> (*)(OpaqueControlRef*, short), GlyphState const*, unsigned char, 
> unsigned char) + 481
> 5   HIView::DragIndicator(CGPoint const&, unsigned long*, void 
> (*)(OpaqueControlRef*, short), GlyphState const*, unsigned char, 
> unsigned char) + 213
> 6   HIView::TrackSelf(OpaqueEventRef*, short*) + 468
> 7   HIView::EventHandler(OpaqueEventHandlerCallRef*, OpaqueEventRef*, 
> void*) + 2531
> 8   DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, 
> HandlerCallRec*) + 1093
> 9   SendEventToEventTargetInternal(OpaqueEventRef*, 
> OpaqueEventTargetRef*, HandlerCallRec*) + 304
> 10  SendEventToEventTargetWithOptions + 55
> 11  SendControlDefTrack(HIView*, CGPoint const&, unsigned long*, void 
> (*)(OpaqueControlRef*, short), OpaqueEventRef*, short*) + 312
> 12  HIView::ClickInternal(CGPoint const&, unsigned long, void 
> (*)(OpaqueControlRef*, short), OpaqueEventRef*, bool) + 160
> 13  HIView::ClickSelf(OpaqueEventRef*) + 371
> 14  HIView::EventHandler(OpaqueEventHandlerCallRef*, OpaqueEventRef*, 
> void*) + 2386
> 15  DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, 
> HandlerCallRec*) + 1093
> 16  SendEventToEventTargetInternal(OpaqueEventRef*, 
> OpaqueEventTargetRef*, HandlerCallRec*) + 304
> 17  SendEventToEventTarget + 56
> 18  HIView::Click(OpaqueEventRef*) + 329
> 19  HandleClickAsHIView + 145
> 20  HandleWindowClick + 507
> 21  HandleMouseEvent + 895
> 22  StandardWindowEventHandler + 86
> 23  DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, 
> HandlerCallRec*) + 1093
> 24  SendEventToEventTargetInternal(OpaqueEventRef*, 
> OpaqueEventTargetRef*, HandlerCallRec*) + 304
> 25  SendEventToEventTarget + 56
> 26  ToolboxEventDispatcherHandler(OpaqueEventHandlerCallRef*, 
> OpaqueEventRef*, void*) + 1169
> 27  DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, 
> HandlerCallRec*) + 2044
> 28  SendEventToEventTargetInternal(OpaqueEventRef*, 
> OpaqueEventTargetRef*, HandlerCallRec*) + 304
> 29  SendEventToEventTarget + 56
> 30  wxApp::MacHandleOneEvent(void*) + 34
> 31  wxApp::MacDoOneEvent() + 108
> 32  wxDialog::DoShowModal() + 98
> 33  wxDialog::Show(bool) + 71
> 34  wxDialog::ShowModal() + 54
> 35  (code that shows my dialog)
> 
> The worker thread:
> 0   semaphore_wait_signal_trap + 7
> 1   MPEnterCriticalRegion + 190
> 2   PostEventToQueueInternal + 234
> 3   PostEventToQueue + 51
> 4   wxMacWakeUp() + 200
> 5   wxWakeUpIdle() + 33
> 6   (the AddPendingEvent call)






More information about the wx-users mailing list