Thread safety of basic_string

Loren James Rittle rittle@latour.rsch.comm.mot.com
Mon Nov 26 21:21:00 GMT 2001


> I'm trying to debug a heavily multi-threaded application that does a lot
> of constructing, concatenating, and destroying of std::string objects. 
> I'm running the code under Solaris 2.8, built with gcc 3.0.2 with
> --enable-threads=posix.

Hi Dan,

I make you the same offer I make everyone that posts a similar request
to this mailing list.  If you can take the time to build a
self-contained test case program that crashes as your application
does, it will be looked at.  I personally guarantee it but I also know
others will as well.  The key is self-contained (i.e. no third-party
libraries or closed-source stuff).  The harder you work to make the
test case small (i.e. one compilation unit and low line count), the
more interested I am in helping you.

We will either explain exactly which design rule you violated or
confirm a bug the standard library (and set about on a fix).

[...]
> So my question is, what can I do to fix this application, which
> obviously expects more thread safety than std::string currently
> provides?  Is ensuring that no single string is ever shared between
> threads enough, or will I always have problems related to
> _S_empty_rep_storage no matter what I do?
[...]

It is very hard to answer this type of question no matter how much
information you provide with no code example of what you think you can
get away with... ;-)  The threading design rules are documented in the
libstdc++-v3 FAQ.  We have recently updated them quite a bit.  Please
start there if you haven't ever read what is expected of your code.

Regards,
Loren
-- 
Loren J. Rittle
Senior Staff Software Engineer, Distributed Object Technology Lab
Networks and Infrastructure Research Lab (IL02/2240), Motorola Labs
rittle@rsch.comm.mot.com, KeyID: 2048/ADCE34A5, FDC0292446937F2A240BC07D42763672



More information about the Libstdc++ mailing list