#include<aomic> class SpinLock{ public: SpinLock():flag_(false){} void lock(){ bool except = false; while(!flag_.compare_exchange_weak(expect,true)) { expect = false; } } void unlock() { flag_.store(false); } private: std::atmoic<bool>flag_; };
#include<aomic> class SpinLock{ public: SpinLock():flag_(false){} void lock(){ bool except = false; while(!flag_.compare_exchange_weak(expect,true)) { expect = false; } } void unlock() { flag_.store(false); } private: std::atmoic<bool>flag_; };