Use std::atomic where appropriate