Make the thread disconnected by calling pthread_detach() on the child thread or by creating the thread in the main thread, set the pthread attributes for this thread to a separate state. Now that the thread is disconnected, you do not need to call pthread_join() on the main thread. Then, in the child thread itself, before exiting the thread, click the event in the event queue of the WxWidgets object that generated the thread to βdeclareβ that the child thread has completed. Finally, add an event handler for the thread completion event to your WxWidget object to handle even the generated thread by placing an event queue in it.
For example, you can create an event such as THREAD_FINISHED_EVENT , which the thread will click on the event queue of the object that will generate the threads. The code will look like this:
wxCommandEvent event(THREAD_FINISHED_EVENT, GetId());
The event itself will be processed in the main WxWidget event stream, which sets a handler for the event. You just need to provide a handler for the WxWidget object and define the event itself. This can be done using the DEFINE_EVENT_TYPE macro, and then add the following construct to the constructor of the WxWidget object, which will spawn the threads themselves:
//myWxWidget::thread_handler is the handler for your thread ending events Connect(widgetID, THREAD_FINISHED_EVENT, wxCommandEventHandler(myWxWidget::thread_handler))
To summarize this, here is what some theoretical WxWidgets object class looks like:
//myWindowThreadClass.hpp #include <wx/wx.h>
Jason source share