Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Is concurrent_unordered_map safe if insert and erase at the same time?

Qiang_W_
Beginner
255 Views

Something confuse me when i use tbb::concurrent_unordered_map, but can I erase the item while updating the other one or inserting a new one? What is unsafe_erase exactly mean?

0 Kudos
1 Reply
RafSchietekat
Black Belt
255 Views

The Reference Manual is pretty clear on that: "The erase methods are prefixed with unsafe_, to indicate that they are not concurrency safe."

Only use such methods while no other threads are accessing the container (the exclusion is per instance even if the documentation does not explicitly say so), or consider using concurrent_hash_map instead.

Reply