Created
August 5, 2014 17:55
-
-
Save daniel-j-h/3fae545d1c2cd1684897 to your computer and use it in GitHub Desktop.
Spinlock: It spins and locks!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <atomic> | |
class spinlock_mutex { | |
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); } | |
private: | |
std::atomic_flag flag; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment