C ++多线程运行时错误:已调用abort()

时间:2017-03-30 15:21:40

标签: c++ multithreading vector

我正在编写一个C ++程序,从时间n = 168到0,基于值W(t + 1)计算后向W(t)。 W(t)是具有负指数的3D修正矢量。我选择在Wt [k] [i] [j]中运行k-multi线程来填充值。单线程版本工作正常,但在多线程上运行时,它报告失败了:report_runtime_error:“abort()已被调用。” (来自主线程)。我试图检查Thread窗口,但找不到太多线索。任何人都可以帮助/指导我如何调试?

(i)如何告诉哪个工作线程导致错误?

(ii)我应该在调试模式中放置一些断点吗?

// class ForwardShootingGrid was created as a modified 3D vector to cater negative index 
ForwardShootingGrid Wt;
ForwardShootingGrid Wtp1;

// as a worker thread 
void ComputeGridValue_LayerK(int n, int i_max, int j_max, int k) {
    ......
    for (int i = -i_max; i <= i_max; i++) {
        for (int j = -j_max; j <= j_max; j++) {
            ......
            x = ......    // x depends on value from ForwardShootingGrid Wtp1
            Wt.AssignGridValue(k, i, j, x);    // to input value=x into Wt[k][i][j]
            ......
        }
    }
}

// as a Main thread
int main(int, char*[]) {
    for (int n = n_max - 1; n >= 0; n--) {    // n is somehow like the time index
        i_max = n;
        j_max = n;
        k_max = ...

        // Everytime copy ForwardShootingGrid Wt to Wtp1, and then recompute Wt which is based on value from Wtp1  
        Wtp1 = Wt;
        // resize Wt
        Wt.ResizeGrid(0, k_max, -i_max, i_max, -j_max, j_max);

        for (int k = 0; k <= k_max; k++) {
            oThreads[k] = std::thread(ComputeGridValue_LayerK, n, i_max, j_max, k);
        }
        for (int k = 0; k <= k_max; k++) {
            oThreads[k].join();
        }
}

0 个答案:

没有答案