[wx-dev] Re: wxString(s.c_str()) thread safety (was Re: wxString threadsafe)

Hajo Kirchhoff mailinglists at hajo-kirchhoff.de
Fri May 2 02:41:21 PDT 2008


Hajo Kirchhoff schrieb:
[...]

> And so on. I will now eliminate wxString from the interfaces of all 
> worker thread classes, so that they either accept a TCHAR* or are using 
> std::basic_string<TCHAR>. The alternative would be a meticuously code 
> reading to examine every occurrence of wxString, determining if it might 
> be shared between threads. Just one copy, even a temporary one, is 
> enough to corrupt the heap.

No, not even that is enough. If I pass a TCHAR* to a method and assign 
it to a member wxString, I still have the wxString-sharing problem.

If the method is called from the GUI thread and the wxString member 
variable accessed from another thread, the problem is still there.

wxString member variables are or course also not thread-safe, regardless 
of the interface of my setter function.

The only viable solution for me is to replace every wxString instance 
with std::basic_string<>.

Or am I missing something? I don't think so.

Best regards

Hajo



More information about the wx-dev mailing list