Skip to content

Instantly share code, notes, and snippets.

@yorung
Created September 20, 2015 08:31
basic spin lock
class Atomic {
std::atomic<int> val = 0;
public:
void Lock()
{
int expected = 0;
while (!val.compare_exchange_weak(expected, 1)) {
expected = 0;
}
}
void Unlock()
{
val.exchange(0);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment