#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_;
};
标签:基于,false,CAS,void,flag,expect,自旋,SpinLock
From: https://www.cnblogs.com/simp/p/17495189.html