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?

  1. A thread with an insertion can be concurrent with another thread with an insertion without using locks.
  2. A thread with an insertion can be concurrent with another thread with a lookup without using locks.
  3. A thread with an insertion can be concurrent with another thread with a traversal without using locks.
  4. A thread with an insertion can be concurrent with another thread with an erasure without using locks.
  5. A thread with an lookup can be concurrent with another thread with an erasure without using locks.
  6. ......
  7. 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

以上是关于TBB concurrent_unordered_map哪些操作可以并发的主要内容,如果未能解决你的问题,请参考以下文章

与 tbb::task_arena 和 tbb::task_scheduler_observer 链接时出错

tbb简介与使用

tbb::parallel_for 实例

TBB的学习

结合英特尔 IPP 和 TBB

TBB 管道的错误输出