TBB concurrent_unordered_map哪些操作可以并发
Posted 软件工程小施同学
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TBB concurrent_unordered_map哪些操作可以并发相关的知识,希望对你有一定的参考价值。
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.
以上是关于TBB concurrent_unordered_map哪些操作可以并发的主要内容,如果未能解决你的问题,请参考以下文章