This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::string & multithreading


On 02/26/2010 12:32 PM, Marc Glisse wrote:
> On Fri, 26 Feb 2010, Radu Marginean wrote:
>> Currently std::string cannot be safely used in a multithreaded
>> environment due to features like copy on write and reference
>> counting. Even programs that access two unrelated different string
>> objects in a multicore machine may suffer random crashes.
> Is that really the case? Last time I checked, the implementation
> didn't use any global/static variables, so no reason for unrelated
> strings to interact,
Note, however, that the empty string object is statically allocated.
Granted, we don't use any reference counting on it - and in any case, as
Marc points out, the reference counts are always changed atomically -
but it can cause problems in some cases. People can avoid *any* form of
static allocation configuring the library with
--enable-fully-dynamic-string. That breaks the binary compatibility however.

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]