I implemented Critical Section like presented in many articles.
Code framework follows
declaration of global device variables;
__device__ int gpnIntArray[3200];
__device__ int gnInt, gnLock;
Host code
int nTemp = 0;
cudaMemcpyToSymbol(gnInt, &nTemp, sizeof(int), 0, cudaMemcpyHostToDevice);
cudaMemcpyToSymbol(gnLock, &nTemp, sizeof(int), 0, cudaMemcpyHostToDevice);
RaceConditionSolution<<<100, 32>>>();
Device code
__global__ void RaceConditionSolution()
{
while (atomicCAS(&gnLock, 0, 1) != 0){}
gpnIntArray[gnInt] = 1;
gnInt ++;
atomicExch(&gnLock, 0);
}
I am about to update global device variables - gpnIntArray[3200] and gnInt.
But, this code makes my pc freeze.
What is the problem? and please help me with solution in this case.
Thanks in advance.