Topic: Are STL strings thread-safe?


Author: sultan@connexus.apana.org.au (Jon Hornstein)
Date: 1997/08/19
Raw View
"John Harris" <harris@clear.com> wrote:

>I'm finding a memory leak in the string deallocate() (on the call to
>impl_->deallocate()) under heavy thread load, and it brings up a
>frightening question:

>What parts, if any, of the STL are thread-safe?

I didn't think STL addresses this issue.

Firstly on a MT safe environment, the RTL would be thread safe. So you
could confidently perform "new" operations without memory managment
crashing.

The question of STL in  MT environment should be seen from two
perspectives.

1. The thorny question of two threads writing to the same container at
the same time. No way. It can be overcome with "monitors",
"semaphores", critical section etc. but these calls aren't inherently
built into the containers, not should they!

2.  But I don't see any reason why two threads wouldn't read or
const_iterate containers concurrently.

Hope this helps

Jon
>john k. harris
>clear communications
>(harris@clear.com)
>---
>[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
>                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
>  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
>  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
>  Comments? mailto:std-c++-request@ncar.ucar.edu
>]
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Dave Derry <dderry@acm.org>
Date: 1997/08/20
Raw View
> "John Harris" <harris@clear.com> wrote:
>
> >I'm finding a memory leak in the string deallocate() (on the call to
> >impl_->deallocate()) under heavy thread load, and it brings up a
> >frightening question:
>
> >What parts, if any, of the STL are thread-safe?
>

Hi John,

It is my understanding that the current version of the STL does not
address the issue of thread safety. However, SGI has an STL version that
is thread-safe. I believe that it also gives the developer the option of
turning off thread-safety if it's not needed.

Check their homepage for more information.

Dave D.
dderry@acm.org
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Boris Goldberg <borisg@ml.com>
Date: 1997/08/21
Raw View
Jon Hornstein wrote:
>
> "John Harris" <harris@clear.com> wrote:
>
> >I'm finding a memory leak in the string deallocate() (on the call to
> >impl_->deallocate()) under heavy thread load, and it brings up a
> >frightening question:
>
> >What parts, if any, of the STL are thread-safe?
>

STL thread safety is implementation-dependent. Check with
your vendor. Many implementations are not thread-safe.
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Matt Austern <austern@isolde.mti.sgi.com>
Date: 1997/08/21
Raw View
Boris Goldberg <borisg@ml.com> writes:

> > >I'm finding a memory leak in the string deallocate() (on the call to
> > >impl_->deallocate()) under heavy thread load, and it brings up a
> > >frightening question:
> >
> > >What parts, if any, of the STL are thread-safe?
> >
>
> STL thread safety is implementation-dependent. Check with
> your vendor. Many implementations are not thread-safe.

One other important point: "thread safety" means different things to
different people.  Programming with threads always involves some
cooperation between the language/library and the programmer; the
crucial queston is exactly what the programmer has to do in order to
get well-defined behavior.

See http://www.sgi.com/Technology/STL/thread_safety.html for an
example of an STL thread-safety policy.  It's not the only conceivable
threading policy, but, as the document says, it is "what we believe to
be the most useful form of thread-safety."
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: "John Harris" <harris@clear.com>
Date: 1997/08/04
Raw View
I'm finding a memory leak in the string deallocate() (on the call to
impl_->deallocate()) under heavy thread load, and it brings up a
frightening question:

What parts, if any, of the STL are thread-safe?

john k. harris
clear communications
(harris@clear.com)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Ross Smith <ross.smith@nz.eds.com>
Date: 1997/08/04
Raw View
John Harris wrote:
>
> I'm finding a memory leak in the string deallocate() (on the call to
> impl_->deallocate()) under heavy thread load, and it brings up a
> frightening question:
>
> What parts, if any, of the STL are thread-safe?

There are three answers to this...

(1) string is not part of the STL. (STL != standard library)

(2) Whether the STL is thread safe is entirely up to the implementor.
The draft standard has nothing to say on the subject. Some
implementations (e.g. Silicon Graphics) are thread safe, some (e.g.
Hewlett Packard) are not.

(3) The string class described in the current draft standard is broken,
and cannot be made thread safe without changing the specification. See
http://www.sgi.com/Technology/STL/design_documents.html

--
Ross Smith ............................. <mailto:ross.smith@nz.eds.com>
Internet and New Media, EDS (New Zealand) Ltd., Wellington, New Zealand
     "I'm as interested as anybody else in all the things no decent
     person would be interested in."          -- Ashleigh Brilliant
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]