0
我的问题:为什么我的程序冻结,如果我使用“只读”const_accessors?TBB ThreadingBuildingBlocks奇怪的行为
它似乎是锁定,从API说明似乎可以有一个访问器和多个const_accessors,(作家,读者)。也许有人可以告诉我一个不同的故事。
我试图实现的目标是使用这个并发哈希映射并将其提供给10-200个线程,以便他们可以查找和添加/删除信息。如果你有比我现在使用的更好的解决方案,那么你也可以发布替代方案。
tbb::size_t hashInitSize = 1200000;
concurrent_hash_map<long int,char*> hashmap(hashInitSize);
cout << hashmap.bucket_count() << std::endl;
long int l = 200;
long int c = 201;
concurrent_hash_map<long int,char*>::accessor o;
concurrent_hash_map<long int,char*>::const_accessor t;
concurrent_hash_map<long int,char*>::const_accessor h;
cout << "Trying to find 200 "<< hashmap.find(t,200) << std::endl;
hashmap.insert(o,l);
o->second = "testother";
TBB Community Tutorial Guide页43说明存取
的
感谢您的快速响应,所以您只是说这只是死锁,因为我没有多线程呢?这个数据结构不应该在并发环境中使用并且永远不会死锁吗? (或者它只是在等待初始锁被释放?)这意味着,它将被允许仅在特定的线程中连续访问数据结构,并且每个线程只能访问一次? – 2012-07-08 18:30:31
您可以并行访问不同的条目,例如并行访问条目200和条目201即可。您无法使用'accessor'与多个线程并行访问单个条目。您的代码尝试获取条目200的所有权,然后再次获取条目200的所有权。这就像访问条目200与两个线程并行。 – Heatsink 2012-07-08 18:42:10