#include // for user-defined resource sections #include struct SpinLock { void lock() { { // define an explicit scope termsec::CheckWait check( &_flag ); while ( _flag.test_and_set() ) { } } // end of scope termsec_begin_exclusive( &_flag ); } void unlock() { termsec_end_exclusive( &_flag ); _flag.clear(); } private: std::atomic_flag _flag = ATOMIC_FLAG_INIT; }; int main() { SpinLock sl; sl.lock(); while ( 1 ) { } }