mardi 21 avril 2020

Is insert() in one thread and at() in multiple other threads thread safe for unordered_map?

My scenario is that there's only one thread inserting elements to an unordered_map and other threads will only use at() for the same map, without using mutex.

insert() may cause rehash so the iterators will all get invalidated in the case. But at() doesn't return iterator actually

mapped_type& at ( const key_type& k );
const mapped_type& at ( const key_type& k ) const;

So why isn't this thread safe, and what problem will be caused?

Aucun commentaire:

Enregistrer un commentaire