Hi all,

I have an issue using my Nvidia card and atomic function atom_xchg, in order to implement semaphor. I need to lock for a work-item an array of float named "v" passing as argument to a kernel function: (below the code). When i launch the kernel the semaphor is initialize with 0 (<=> the resource is available)

Code :
__kernel void my_ker (__global float* v, __global int* semaphor)
// Retrieve the index of the work-item
int g = get_global_id(0);

// wait for resurce to be available
while (atom_xchg (semaphor, 1) != 0) {}

// use the array for the current work-item
v[g] = (float)g;

// unlock the resource
atom_xchg (semaphor, 0);


But the program crashes all the timeand i do not understand why? Could someone help me please and explain me why it does not work correctly