There are, as always many different solutions to this problem.
Basic integer operations are usually atomic on most systems. But you have to make sure, the variable is not cached, and that the basic operation can be done in one step. So setting the integer to 0 would be such a basic operation. But increasing it's value by one, or change one bit somewhere isn't. Cause there you are reading the current state, calculating the new one, and finally writing it back. Another thread doing the same thing simultaneously would lead to an inconsistent state. (as an example a variable that was increased twice, but it's value is only one more)
One solution would be to surround access to this integer with locks.
Another and faster approach would be to use a compare_and_set method for writing. (reading should be no problem) In this case, make sure your variable is not cached in one of the CPUs, as an example by declaring it volatile.
This could be helpful for you;
bool __sync_bool_compare_and_swap (type *ptr, type oldval type newval, ...)
type __sync_val_compare_and_swap (type *ptr, type oldval type newval, ...)
These builtins perform an atomic compare and swap. That is, if the current value of *ptr is oldval, then write newval into *ptr.
The “bool” version returns true if the comparison is successful and newval was written. The “val” version returns the contents of *ptr before the operation.
I have this part from here: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html
Using compare and set correctly, you can make sure the variable is only modified, if nobody else is doing it at the same time. Therefore you need to use it inside a while loop as shown in this thread here: How to compare and swap atomically in ARM7?
A third approach would be to head for a library which provides you a long list of many different "Atomic-Operations". This might be the cleanest way.
Doing the handling yourself using volatile and compare-and-set might be dangerous, as it won't warn you or others if the special treatment of the variable was forgotten somewhere.
one last thing. Please be informed, that the unprotected read access only works with a single integer variable. If you are working with a double, or with two integers, you might get an inconsistent state. Where during a write of process 0, half of the double variable (or one integer of two) already has the new value and the other part still the old value while you read it in thread 1. This would directly lead to a hard to find bug. Rarely happening, but disaster when it does. (This part applies only to common 32bit CPU systems. Certain smaller systems might handle memory in smaller chunks. 64bit systems on the other hand, usually handle two integers (64bit) as one chunk, there it would work with the double, but not with bigger constructs)
good luck!