c – Tbb并发哈希映射迭代器
作者:互联网
我正在使用迭代器遍历整个tbb并发哈希映射并检查每个(键,值)对.
for (MAP::pair = myHashTable.begin(); myHashTable.end(); pair++)
如何并行化这个迭代器?
解决方法:
使用Reference Manual中描述的range()方法:
HashTable_t myHashTable; // assuming HashTable_t is concurrent_hash_map specialization
tbb::parallel_for( myHashTable.range(), [](const HashTable_t::range_type &r) {
for( HashTable_t::iterator i = r.begin(); i != r.end(); i++);
} );
(我使用c++11进行简洁,但为了c++03明确地显示了类型)
请注意那里的注意事项:
Do not call concurrent operations, including count and find while iterating the table. Use concurrent_unordered_map if concurrent traversal and insertion are required.
标签:c,multithreading,parallel-processing,tbb,c++11,c++03 来源: https://codeday.me/bug/20190830/1771546.html