我有一个串行运行的算法,我打算将它并行化。现在,该算法使用 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/