您当前的位置: 首页 >  c++
  • 0浏览

    0关注

    1477博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++ tbb unsafe_erase() 并发访问 解决方案

软件工程小施同学 发布时间:2021-09-22 19:25:56 ,浏览量:0

加锁

/*

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 lock(m_eraseMutex);

        _map.unsafe_erase(_key);

}

关注
打赏
1665320866
查看更多评论
立即登录/注册

微信扫码登录

0.0713s