#ifndef _ATOMIC_LOCK_HPP_ #define _ATOMIC_LOCK_HPP_ #include struct atomic_lock { std::atomic&mutex_; atomic_lock (std::atomic&mutex) :mutex_(mutex) { int ex=0; while(!mutex_.compare_exchange_weak(ex,1)) { } } ~atomic_lock() { mutex_.store(0); } }; #endif