Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread safety question on co/instanceCache.cpp #96

Closed
hernando opened this issue Apr 2, 2014 · 6 comments
Closed

Thread safety question on co/instanceCache.cpp #96

hernando opened this issue Apr 2, 2014 · 6 comments

Comments

@hernando
Copy link

hernando commented Apr 2, 2014

Is it thread safe to return a reference in:

const InstanceCache::Data& InstanceCache::operator[]( const UUID& id )

?

I don't see the lock being returned as part of InstanceCache::Data.

@hernando
Copy link
Author

hernando commented Apr 2, 2014

OK. I see that the semantics of release and operator[] guarantee that the data should not be deallocated while in use. Just a minor question then, does stde::hash_map guarantee that the iterators are not invalidated by insertions?

@eile
Copy link
Member

eile commented Apr 2, 2014

Good question: I haven't paid attention. Can you look into it?

@hernando
Copy link
Author

hernando commented Apr 2, 2014

The MSVC version doesn't invalidate them:

Each element contains a separate key and a mapped value. The sequence is represented in a way that permits lookup, insertion, and removal of an arbitrary element with a number of operations that is independent of the number of elements in the sequence (constant time) -- at least in the best of cases. Moreover, inserting an element invalidates no iterators, and removing an element invalidates only those iterators which point at the removed element.

SGI's documentation on std::hash_map says that resizing doesn't invalidate either:

[3] Resizing does not invalidate iterators; however, it does not necessarily preserve the ordering relation between iterators...

If gcc agrees with the original STL specification (not the C++ Standard Library), it should be save.

@eile
Copy link
Member

eile commented Apr 2, 2014

Thanks. Iirc the gcc STL is the SGI/HP STL.

@eile
Copy link
Member

eile commented Apr 2, 2014

Can be closed?

@hernando
Copy link
Author

hernando commented Apr 2, 2014

I think so

@hernando hernando closed this as completed Apr 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants