wxWidgets calls in secondary threads
All threads other then the "main application thread" (the one wxApp::OnInit or your main function runs in, for example) are considered "secondary threads". These include all threads created by wxThread::Create or the corresponding constructors.
GUI calls, such as those to a wxWindow or wxBitmap are explicitly not safe at all in secondary threads and could end your application prematurely. This is due to several reasons, including the underlying native API and the fact that wxThread does not run a GUI event loop similar to other APIs as MFC.
A workaround that works on some wxWidgets ports is calling wxMutexGUIEnter before any GUI calls and then calling wxMutexGUILeave afterwords. However, the recommended way is to simply process the GUI calls in the main thread through an event that is posted by either wxPostEvent or wxEvtHandler::AddPendingEvent. This does not imply that calls to these classes are thread-safe, however, as most wxWidgets classes are not thread-safe, including wxString.
Partager