Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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映射抛出SIGSEGV_C++_Multithreading_Parallel Processing_Tbb_Mingw32 - Fatal编程技术网

C++ tbb::并发\u散列\u映射抛出SIGSEGV

C++ tbb::并发\u散列\u映射抛出SIGSEGV,c++,multithreading,parallel-processing,tbb,mingw32,C++,Multithreading,Parallel Processing,Tbb,Mingw32,我正在运行一个小程序,它是在Windows和mingw32上使用TBB构建的。它为每个人做了一个平行的实验。在“我的对象”的并行\u中,对并发\u散列\u映射对象进行更改。它开始运行,但当我尝试使用访问器时,它会抛出一个SIGSEGV。我不知道问题出在哪里 我的目标: class Foobar { public: Foobar(FoobarParent* rw) : _rw(rw) { _fooMap = &_rw->randomWalkers();

我正在运行一个小程序,它是在Windows和mingw32上使用TBB构建的。它为每个人做了一个平行的实验。在“我的对象”的并行\u中,对并发\u散列\u映射对象进行更改。它开始运行,但当我尝试使用访问器时,它会抛出一个SIGSEGV。我不知道问题出在哪里

我的目标:

class Foobar
{
public:
    Foobar(FoobarParent* rw) : _rw(rw)
    {
        _fooMap = &_rw->randomWalkers();
    }

    void operator() (const tbb::blocked_range<size_t>&r ) const
    {
        for(size_t i = r.begin(); i != r.end(); ++i)
        {
            apply(i);
        }
    }

private:
    void apply(int i) const
    {
        pointMap_t::accessor a;
        _fooMap->find(a, i);
        Point3D current = a->second;
        Point3D next = _rw->getNext(current);

        if (!_rw->hasConstraint(next))
        {
            return;
        }

        a->second = next;
    }

    FoobarParent* _rw;
    pointMap_t* _fooMap;
};
class Foobar
{
公众:
Foobar(FoobarParent*rw):\u rw(rw)
{
_fooMap=&_rw->randomWalkers();
}
void运算符()(常数tbb::阻塞的\u范围和r)常数
{
对于(大小i=r.begin();i!=r.end();++i)
{
适用(i);
}
}
私人:
无效应用(int i)常量
{
pointMap_t::访问器a;
_fooMap->find(a,i);
点3D电流=a->秒;
Point3D next=\u rw->getNext(当前);
如果(!\u rw->hasConstraint(下一步))
{
返回;
}
a->second=下一个;
}
FoobarParent*_rw;
点地图;
};
点映射定义为:

typedef tbb::concurrent_hash_map<int, Point3D> pointMap_t;
typedef tbb::concurrent\u hash\u map pointMap\t;

有人能解释一下这个问题吗?我是TBB的新手。当apply方法调用->秒时抛出该信号。

此代码中有两个潜在问题

首先,如果
find()。您应该使用
insert()
重写它,这将确保元素的存在,或者添加如下条件检查:

if( a ) // process it

其次,在访问器的锁下调用getNext和hasConstraint。调用锁下的任何东西都是危险的,因为它内部可能有另一个锁,或者调用TBB,因此可能导致死锁或其他问题。

此代码中有两个潜在问题

首先,如果
find()。您应该使用
insert()
重写它,这将确保元素的存在,或者添加如下条件检查:

if( a ) // process it

其次,在访问器的锁下调用getNext和hasConstraint。调用锁下的任何东西都是危险的,因为它可能有另一个锁在里面或调用TBB,从而导致死锁或其他问题。

最好在TBB论坛上提问。此外,您还必须向我们展示如何为函数调用并行_。@Nav感谢您的评论。我最终在没有使用TBB的情况下重写了这个应用程序。下次我尝试TBB时,我将使用TBB论坛。非常感谢。问这个问题的最佳地点是TBB论坛。此外,您还必须向我们展示如何为函数调用并行_。@Nav感谢您的评论。我最终在没有使用TBB的情况下重写了这个应用程序。下次我尝试TBB时,我将使用TBB论坛。非常感谢。