This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Definitive answer about thread-safety of std::string
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Chad Attermann <chad at broadmind dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Thu, 15 Nov 2007 20:43:51 +0100
- Subject: Re: Definitive answer about thread-safety of std::string
- References: <225a01c827bc$0a8bad00$ccca46a6@office>
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.