I see someone said it is not necessary when you are using pthreads.
I'm not sure how pthread works to protect such case , but as I know it is important to
define a global variable as "volatile" if you are in multi-thread environment,
the reason is like myrkos said above , multi thread env is the case that the variable could
be modified "externally" . Modern compile does more optimizing than you thought , it will
make the code not read the value from memory if it THINKs the variable is not modified , however in such an env the variable could change .
But it is not enough to make global variable work well , you need use automic operations or
mutex to protect it .