semaphore? serialize threads?

we have this code below…

*syncthread here*

*gg=*gg+1; 

if (*gg > length) 

cs[coords(1,length*2,cols)] = 0; 

cs[coords(1,*nc,cols)] = x; 

cs[coords(2,*nc,cols)] = y;

after stopping all the threads there at syncthread… how can we possibly count the threads? or perhaps serialize them this time?

these codes are in the kernel…

uh, use atomic operations?