Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ tbb中的错误::并发\u无序\u多重映射?即使是单线程,条目也会丢失_C++_Hashmap_Unordered Map_Tbb - Fatal编程技术网

C++ tbb中的错误::并发\u无序\u多重映射?即使是单线程,条目也会丢失

C++ tbb中的错误::并发\u无序\u多重映射?即使是单线程,条目也会丢失,c++,hashmap,unordered-map,tbb,C++,Hashmap,Unordered Map,Tbb,我的理解是,如果我只使用一个线程,那么tbb::concurrent\u unordered\u multimap的行为应该类似于std::unordered\u multimap。但是,在本例中,它不: #include "tbb/concurrent_unordered_map.h" #include <iostream> #include <unordered_map> struct myhash { size_t operator()(const int

我的理解是,如果我只使用一个线程,那么
tbb::concurrent\u unordered\u multimap
的行为应该类似于
std::unordered\u multimap
。但是,在本例中,它不:

#include "tbb/concurrent_unordered_map.h"
#include <iostream>
#include <unordered_map>

struct myhash {
    size_t operator()(const int& a) const {
        return 1;
    }
};

int main() {
    tbb::concurrent_unordered_multimap<int, int, myhash> tbbidx;
    std::unordered_multimap<int, int, myhash> stdidx;

    for(int i = 0; i < 100; ++i) {
        tbbidx.insert(std::make_pair(i % 10, i));
        stdidx.insert(std::make_pair(i % 10, i));
    }

    std::cout << "tbb size " << tbbidx.size() << std::endl;
    std::cout << "tbb count " << tbbidx.count(0) << std::endl;
    std::cout << "std size " << stdidx.size() << std::endl;
    std::cout << "std count " << stdidx.count(0) << std::endl;
}
如果我删除
myhash
,我会得到正确的结果。然而,我对hashmaps的理解是,一个糟糕的哈希函数只会影响性能,而不会影响正确性,只要该函数在
x==y
mdsl时返回相同的值

问题出在
内部\u insert()
中。
i/10
i%10
不起作用的地方工作的原因是将项目插入多重映射的顺序,这是错误的症状
internal_insert
没有进行键相等性比较,因此每次插入都在列表的末尾(所有散列都相等,因此该方法只是走到末尾。)使用
i/10
时,插入所有0键,然后插入所有1键,依此类推<代码>内部_equal_range检查键的相等性,并正确找到范围的结尾

非常感谢您找到这个bug。我正在添加一个“退化散列”单元测试,我仍然需要弄清楚为什么我们的验证器没有捕获无序列表

问候,, 克里斯


(很抱歉,我把关键方程弄错了…

另外,如果您执行有序插入(
I/10,I
而不是
I%10,I
),则一切正常。如果您声明
volatile size\u t one=1
返回一个
而不是
返回一个
?我很好奇是否有什么东西被优化掉了,因为所有的散列都是相等的,不会改变任何东西。另外,我使用
-O0
.Update编译:在查看了TBB代码之后,我非常确定这是一个具有内部相等范围和多重映射的bug。等待英特尔确认。
tbb size 100
tbb count 1
std size 100
std count 10