Add support for atomic operations
Various places in the code use unsafe non-atomic operations on variables shared between threads. Add some functions to atomically manipulate integers/pointers, so that thread-safe code can be more easily written.
Various places in the code use unsafe non-atomic operations on variables shared between threads. Add some functions to atomically manipulate integers/pointers, so that thread-safe code can be more easily written.