0
以下程序使用'Cuda By Example'实现原子锁,但运行该程序会冻结我的机器。 有人能告诉我我的程序有什么问题吗?非常感谢CUDA中的原子操作
益肺
#include <stdio.h>
__global__ void test()
{
__shared__ int i, mutex;
if (threadIdx.x == 0) {
i = 0;
mutex = 0;
}
__syncthreads();
while(atomicCAS(&mutex, 0, 1) != 0);
i++;
printf("thread %d: %d\n", threadIdx.x, i);
atomicExch(&mutex,0);
}
上面的程序只是我想要做的一个例子。我知道我可以在上面的例子中使用atomicAdd来增加i。然而,在我的真实情况下,关键部分更复杂 – user11869 2012-01-18 21:30:36