Skip to content

Thread safety for changing values of keys already in ordered_map #46

@ericonr

Description

@ericonr

Hi!

I'm using this project's ordered_map. The values under the keys can change, but after the map is first populated, the keys always remain the same. In that situation, in a multithreaded program, is it safe to overwrite the value under one key from thread 1 while accessing another key from thread 2?

I took a look at https://tessil.github.io/ordered-map/classtsl_1_1ordered__map.html#details

insert, emplace, emplace_hint, operator[]: when a std::vector is used as ValueTypeContainer and if size() < capacity(), only end(). Otherwise all the iterators are invalidated if an insert occurs.

From that quote, is it correct that simply changing the value under one key isn't an "insertion" (as defined in something like cplusplus docs for std::unordered_map: adding a new element to the map) and therefore even an ordered_map using std::deque isn't invalidating its iterators (and therefore, can access values under other keys from another thread safely)?

If my understanding is correct and you think it makes sense, I could try my hand at updating the docs to make them clearer on this point.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions