Files
concurrency-in-action/source/listing_5.1.cpp
2014-04-22 21:54:16 -04:00

17 lines
303 B
C++

class spinlock_mutex
{
std::atomic_flag flag;
public:
spinlock_mutex():
flag(ATOMIC_FLAG_INIT)
{}
void lock()
{
while(flag.test_and_set(std::memory_order_acquire));
}
void unlock()
{
flag.clear(std::memory_order_release);
}
};