Topic: if(STL != THREAD_SAFE) throw(OUT_THE_DAMN_WINDOW);


Author: "Jim Lears" <jiml@icommunicate.com>
Date: 1999/12/28
Raw View
is the damn [] operator on a std::map thread safe?

I am forced to put access to that op in a critical section....very very
hurtfull to my performance.



[ 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: James Kuyper <kuyper@wizard.net>
Date: 1999/12/28
Raw View
Jim Lears wrote:
>
> is the damn [] operator on a std::map thread safe?
>
> I am forced to put access to that op in a critical section....very very
> hurtfull to my performance.

Thread safety is not addressed by the current standard in any context.
You can debate whether that was a good idea, but that's the way it is
and will remain for nearly another decade. It's left up to each
implementor to decide whether or not and how to address thread safety
issues. Check your implementation's documentation, and if it doesn't say
anything about thread safety, ask your implementor. Building up a body
of experience with how thread safety should be addressed, should
increase the likelihood of getting something about it being put into the
next release of the standard.
---
[ 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: Dietmar Kuehl <dietmar.kuehl@claas-solutions.de>
Date: 1999/12/28
Raw View
Hi,
In article <_aX94.18157$1t2.323761@news.rdc1.md.home.com>,
  "Jim Lears" <jiml@icommunicate.com> wrote:
> is the damn [] operator on a std::map thread safe?

The standard does not know anything about threads and thus does not
require thread safety. However, normally the library implementations
are thread safe in some sense. See
<http://www.sgi.com/Technology/STL/thread_safety.html> for a discussion
of these issues.

> I am forced to put access to that op in a critical section....very
> very hurtfull to my performance.

If you are accessing the same container from multiple threads and each
individual access to the 'operator[]()' is all you are doing, then this
might be what is necessary and the containers could not do it better
anyway: They would have to protect their code with a similar approach
just that it would always be the case, ie. the bad performance would be
there even if you don't use threads.

Depending on your needs, it might be better to use the 'find()' method
instead of 'operator[]()' because this will not modify the container
and this is normally thread safe. However, if one thread might change
the container, this is no option and it is likely that you have to
protect your container.
--
<mailto:dietmar.kuehl@claas-solutions.de>
homepage: <http://www.informatik.uni-konstanz.de/~kuehl>


Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: rmacombe@nevis.u.arizona.edu (Robert J Macomber)
Date: 1999/12/28
Raw View
In article <_aX94.18157$1t2.323761@news.rdc1.md.home.com>,
Jim Lears <jiml@icommunicate.com> wrote:
>is the damn [] operator on a std::map thread safe?
>
>I am forced to put access to that op in a critical section....very very
>hurtfull to my performance.

The standard says nothing about thread safety.  Your implementation
might - SGI's, for example, is thread safe as long as you don't access
a single object concurrently from two different threads.

If you are trying to use operator[] on a single object from two
threads, what do you expect to happen?  You're accessing a shared
resource concurrently - that's the very *definition* of a critical
section.
--
Rob Macomber
rmacombe@u.arizona.edu
---
[ 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              ]