1
我試圖到正在運行的任務中使用TBB :: concurrent_hash_map掛,但我運行到這個問題,調用地圖的擦除()導致無限鎖的任務。任何想法下面的代碼片段可能是錯誤的?TBB task_group使用concurrent_hash_map時
#include <iostream>
#include <boost/date_time.hpp>
#include <tbb/concurrent_hash_map.h>
#include <tbb/task_group.h>
#include <tbb/task_scheduler_init.h>
class BusyTask
{
public:
void operator()() {
typedef tbb::concurrent_hash_map<unsigned int, int> MyMap;
MyMap m;
MyMap::accessor a;
m.insert(a, 1);
m.erase(1); // The task will lock up at this point
}
};
int main(int argc, char* argv[])
{
std::cout << "Started" << std::endl;
BusyTask busyTask1;
tbb::task_group taskGroup;
taskGroup.run(busyTask1);
taskGroup.wait();
std::cout << "Finished" << std::endl;
return 0;
}
我和TBB V4.0.5測試,GCC 4.7
嘗試將範圍的訪問,例如: {MyMap中::訪問; m.insert(a,1); m.erase(1);} m.erase(1); //任務將鎖定在這個點 – Rick
完美,這是有效的。謝謝! 我應該多一點仔細閱讀了「訪問」文檔:[併發訪問(http://software.intel.com/sites/products/documentation/doclib/tbb_sa/help/reference/containers_overview/concurrent_hash_map_cls/concurrent_access。 HTM) – amoskahiga