[wx-dev] wxString counting thread-safe?

Armel Asselin asselin.armel at wanadoo.fr
Tue Aug 8 08:15:03 PDT 2006


> AA> I'm in front of a problem with wxString. It seems that its reference
> AA> counting is not thread-safe (that of wxObject is not as well).
>
> It isn't. You need to protect accesses to wxString from different threads
> with a mutex/critical section but this is fine, of course. What is not 
> fine
> is that if you want to pass a wxString to another thread you *must* use
> c_str() method or something equivalent to forcefully break string sharing
> across threads.
unfortunately, doing c_str( ) or such is not an option for me, because it is 
the container object which is shared (a wxURI) within a still bigger 
container object. I _must_ have wxString reference counting thread-safe.
Because of the very cool implications of the "copy on write" rules, just 
changing the ++ and -- to interlocked increment / decrement is enough to 
reach our target (the only constraint is that during the data copy the old 
Lock must be maintained). Once that's done, it is practically impossible to 
have more problems (unless wxString was coded the grunt way but I really 
don't think so).

so i _will_ do that change, the question is were should I introduce the 
interlock functions to annoy the less people/have best acceptance of the 
patches. after that i'll propose patches and wx developpers do what they 
like of them.

Armel





More information about the wx-dev mailing list