void unlock() { // To be safer: // // asm volatile ( // "movl %1, %0" // : "=m" (status) // : "r" (UNLOCKED) // : "memory" // ); // But actually we can do this: status = UNLOCKED; }
do { asm volatile("..."); } while (expected != UNLOCKED); sum++; status = UNLOCKED;
atomic_xchg
pthread_mutex_lock