C++ tbb unsafe_erase() 并发访问怎么办

Posted 软件工程小施同学

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++ tbb unsafe_erase() 并发访问怎么办相关的知识,希望对你有一定的参考价值。

加锁

/*

NOTICE:

m_eraseMutex is used for eraseKey() method with tbb::concurrent_unordered_map

instance only. Because in that eraseKey() method, we use unsafe_erase() method to delete element

in tbb::concurrent_unordered_map instance. As "unsafe_" prefix says, the unsafe_erase() method

can NOT ensure concurrenty safety between different calls to this method, that's why we used a

mutex to ensure there is only one thread can erase element each time.

Additionally, by now no evidence shows that unsafe_erase() method would conflict with insert()

or find() method. To get furthur details about the data structure used in

tbb::concurrent_unordered_map, maybe you could read:

http://www.cs.ucf.edu/~dcm/Teaching/COT4810-Spring2011/Literature/SplitOrderedLists.pdf

*/

std::mutex m_eraseMutex;

void eraseKey(ConcurrentMap& _map, KeyType const& _key)

{

std::lock_guard<std::mutex> lock(m_eraseMutex);

_map.unsafe_erase(_key);

}

以上是关于C++ tbb unsafe_erase() 并发访问怎么办的主要内容,如果未能解决你的问题,请参考以下文章

C++ tbb::concurrent_hash_map怎么用

需要帮助英特尔 TBB 工作吗?

tbb 并发容器性能

TBB concurrent_unordered_map哪些操作可以并发

C++ TBB 文档手册地址

C++ tbb::atomic<bool> 声明读取重新赋值