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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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::mapdoes not invalidate existing iterators (see Does insertion to STL map invalidate other existing iterator?)