Syncing threads that access same memory location

Can anyone tell me how to sync threads which are in different blox that try to increment the value by 1 at a specific array index ? for example i want to create an image histogram so i have an array of size 256, value at each index corresponds to the number of pixels of that graylevel in the image.

Atomic Functions in B.10 of programming guide