There are two functions which can send events from a worker thread to main GUI.
wxPostEvent() and AddPendingEvent()
According to the discussions below:
I think there are many issues in our C::B source:
wxCommandEvent is not thread safe for its m_cmdString member, e.g.:
wxString message;
wxCommandEvent evt(...);
evt.SetString(message.c_str());
wxPostEvent(m_Parent, evt);
The code snippet is not thread safe, because "evt" and the cloned wxCommandEvent shared the same wxString member buffer.
CodeBlocksEvent is not thread safe, e.g. in cbthreadpool.cpp
CodeBlocksEvent evt = CodeBlocksEvent(cbEVT_THREADTASK_ALLDONE, m_ID);
wxPostEvent(m_pOwner, evt);
CodeBlocksEvent is a derived class from wxCommandEvent, and I don't see it Clone its m_strString.
3, I'm not sure PipedProcess class has such issue, because its related to send event cross processes.
Solution:
If the event need to carry wxString from worker thread to main GUI thread, we should implement a Clone method which deep copy its m_cmdString. Just like the new event type wxThreadEvent in wx 2.9.x.
Any comments.