As stated in the document (concurrent_unordered_map — oneAPI Specification 1.0-rev-3 documentation).
tbb::concurrent_unordered_map is a class template that represents an unordered associative container. It stores key-value pairs with unique keys and supports concurrent insertion, lookup, and traversal, but does not support concurrent erasure.
Does it mean the following?
- A thread with an insertion can be concurrent with another thread with an insertion without using locks.
- A thread with an insertion can be concurrent with another thread with a lookup without using locks.
- A thread with an insertion can be concurrent with another thread with a traversal without using locks.
- A thread with an insertion can be concurrent with another thread with an erasure without using locks.
- A thread with an lookup can be concurrent with another thread with an erasure without using locks.
- ......
- A thread with an erasure can not be concurrent with another thread with an erasure without using locks.
Am I right? Looking forward to your reply, thank you very much.
Thank you for your question! You are right, concurrent_unordered_map
can be used by different threads with insertion, traversal and lookup without any additional synchronization.
Erasure operations (as well as any other operations, such as clear
, assignment operators, bucket interfaces, swap
, etc.) can not be used simultaneously with other operations. Such a methods can only be used in "serial" parts of the application, when other threads do not perform any operations on the container. In concurrent part, it can be achieved with writer lock around the unsafe operation.
I am very confused about which operations can be concurrent · Issue #640 · oneapi-src/oneTBB · GitHub