Topic: Immutable strings and threads


Author: dhunter@lehman.com
Date: 1999/03/12
Raw View
Hi,

When designing the string classes in the standard library was an
immutable string class considered.

The rational for this is that the aquistion and release of mutext locks,
in a multi threaded program,  on the standard string class are not necessary
when a string is created that will never be modified.

Obviously only a subset of the member fuctions of the standard string class
would be avaiable on such a class.


David Hunter

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: hinnant@_anti-spam_lightlink.com (Howard Hinnant)
Date: 1999/03/12
Raw View
In article <7c8fgc$t96$1@nnrp1.dejanews.com>, dhunter@lehman.com wrote:

> Hi,
>
> When designing the string classes in the standard library was an
> immutable string class considered.
>
> The rational for this is that the aquistion and release of mutext locks,
> in a multi threaded program,  on the standard string class are not necessary
> when a string is created that will never be modified.
>
> Obviously only a subset of the member fuctions of the standard string class
> would be avaiable on such a class.

Yes, it's called const string.  However if you make a const copy of the
const string, you must still protect the refcount in the destructor** so
that the threads can agree who will delete the data.

**Footnote: Or otherwise assure that the decrement and test operation on
the refcount is atomic.

-Howard


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]