小编Sam*_*Sam的帖子

c、openmp的CAS实现

我正在尝试实现比较和交换操作,以便我的线程知道是否根据 value 进入特定区域u_parent。我只是想知道这是否是正确的实现方法以及我是否在某个地方出错了。

int *u_parent;
u_parent = &graph->parents[u]; 

if (*u_parent < 0) { 
    // This region should only be entered by each thread
    // if the value of u_parent is < -1.   

    graph->parents[u] = v;
    // ^-- If region is entered, this value is modified
    // by some variable v

    //Swap:
    u_parent = &graph->parents[u];

    DO_SOMETHING();
}
Run Code Online (Sandbox Code Playgroud)

这个实现是否正确,因为我仍然看到其他线程在 CAS 操作后进入该区域?

c multithreading openmp

0
推荐指数
1
解决办法
1044
查看次数

标签 统计

c ×1

multithreading ×1

openmp ×1