This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Subtle MT problem with __gnu_cxx::hash_map


> -----Original Message-----
> From: Nathan Myers [mailto:ncm-nospam@cantrip.org]
> Sent: Friday, November 19, 2004 4:15 PM
> To: libstdc++@gcc.gnu.org
> Subject: Re: Subtle MT problem with __gnu_cxx::hash_map
> 
> On Fri, Nov 19, 2004 at 03:45:24PM -0500, Paul Dubuc wrote:
> >
> >
> > Matt Austern wrote:
> >
> > >
> > >
> > >But operator[] isn't read access.  It's defined to be equivalent to
a
> > >certain form of insert().
> >
> > Not just insert() but find() too.  So it's both read and write
access.
> I
> > think there's enough ambiguity to warrant the simple change I
suggested
> if
> > it's really feasible.
> 
> The problem Paul Dubuc has noted is that the expected failure is too
> uncertain, so that his code passed testing for too long before the
> coding mistake was detected.
> 
> Thus, I would argue for opposite action: if it can be done without
> hurting performance for regular users, then any use of op[] should
> be very likely to fail when used in a shared context without locking
> -- regardless of whether the operation actually has any externally-
> visible need to change the container.   Similarly, we should
> scribble the storage that was occupied by a container element,
> after it is removed.  It would probably be better to do this sort
> of thing in a debug-mode version of the library.

Following in these lines: One thing possibly worth considering here is
to adopt the 'fail-fast' approach that Java takes for java.util.HashMap
(which is not thread-safe), at least for debugging.

Java HashMaps maintains a modification count, and each iterator gets a
copy. If the current copy gets out of date, it means that there has been
a concurrent modification, which is unsafe (you then get a
ConcurrentModificationException).

http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

> Nathan Myers
> ncm-nospam@cantrip.org

--
Emery Berger
Assistant Professor
Dept. of Computer Science
University of Massachusetts, Amherst
www.cs.umass.edu/~emery


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]