Replaced volatile variables with C++11 atomics