Files
concurrency-in-action/source/listing_7.1.cpp
2018-10-18 00:40:34 -05:00

15 lines
286 B
C++

#include <atomic>
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); }
};