c++ - C++ 中的 concurrent_unordered_map

标签 c++ parallel-processing tbb

我有一个串行运行的算法,我打算将它并行化。现在,该算法使用 C++11 中的 unordered_map。我可以直接用 concurrent_unordered_map 代替它吗?

我只想指出,我已尝试这样做,但它似乎会产生难以理解的错误。就像这个:

(.text._ZN3tbb13tbb_allocatorINS_10interface58internal18split_ordered_listISt4pairIKSsSt6vectorIjSaIjEEENS0_IS9_EEE4nodeEE8allocateEjPKv[tbb::tbb_allocator<tbb::interface5::internal::split_ordered_list<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned int, std::allocator<unsigned int> > >, tbb::tbb_allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<unsigned int, std::allocator<unsigned int> > > > >::node>::allocate(unsigned int, void const*)]+0x16): undefined reference to `tbb::internal::allocate_via_handler_v3(unsigned int)'

最佳答案

concurrent_unordered_map 允许并发插入和并发读取,但不允许并发删除。所以只要你在添加/迭代时不删除你应该没问题。

  • 上面评论中提到的链接问题。

关于c++ - C++ 中的 concurrent_unordered_map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10064850/

相关文章:

c++ - 查找并行化 C/C++ 的第 n 个排列

c++ - 我可以为 argv 赋值吗?

python - 为什么在使用 Python 多处理池时会有空闲的工作线程?

parallel-processing - 任务怎么写? (平行码)

c++ - 具有高多线程的 TBB 4.2 内存泄漏

c++ - Concurrent_hash_map 实现抛出 SIGSEGV

c++ - 待定并发容器性能

c++ - 从指针到成员的映射

c++ - 调用 Const 函数指针

algorithm - 并行处理的计算顺序