I have a thread (Thread A) which continuously iterates over a map say MapA.
Now there is an other thread (ThreadB) which inserts elements into the MapA.
I dont delete elements from MapA
Will there be any concurrency issue by this operation?
I have a thread (Thread A) which continuously iterates over a map say MapA.
Now there is an other thread (ThreadB) which inserts elements into the MapA.
I dont delete elements from MapA
Will there be any concurrency issue by this operation?
There is a distinction between thread safety / concurrency issues and invalidating iterators when inserting new items.
The STL is inherently not thread-safe, so be sure to mutex-lock when doing anything else than just reading from an STL object from multiple threads.
However, inserting into a std::map
does not invalidate existing iterators (see Does insertion to STL map invalidate other existing iterator?)