synchronization problem

i have a problem with my code.

if((d_gpu[id]<Node_weight_gpu[id])&& status_gpu[id]==0)



now i want that at a time only one thread can access the statement *no_of_nodes_gpu=*no_of_nodes_gpu-1…
so i used after this line…but its not giving proper i am new to this.can anyone tell me how can i do this or is this a correct method to do.And,i want to do this across blocks.

please reply as soon as possible…
Thanks in advance

Use atomicAdd(no_of_nodes_gpu, -1) instead.