You will want to use memory barriers or fences: see http://en.wikipedia.org/wiki/Memory_barrier
In the Linux kernel you can use the rmb()
or wmb()
calls.
Under pthreads
you can use pthread_barrier_wait()
, though that doesn't appear to be in my pthreads manpages.
On MSVC, look at Force order of execution of C statements? - which also has some good general information.
If you find an 'atomic' library, that will normally include barrier functions.