Definitive answer about thread-safety of std::string
Paolo Carlini
pcarlini@suse.de
Thu Nov 15 19:43:00 GMT 2007
Hi,
> While libstdc++ documentation makes it clear that the library is
> thread-safe as long as an object is locked so that only a single
> concurrent thread can access it, I have seen some conflicting
> statements elsewhere that elude to the fact that std::string may be
> safe for access by concurrent threads. I would appreciate if anyone
> could enlighten me on whether std::string is in fact safe for access
> by concurrent threads without explicit locking, or if it requires a
> read-write locks or a full locks instead.
you can find rather complete details in this PR
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334
in particular James' initial analysis is correct. If you want, we are
already delivering an alternate implementation under <ext/vstring.h>,
which by default doesn't use reference counting and can be more suited
for some applications. By now is pretty stable.
Paolo.
More information about the Libstdc++
mailing list