typedef struct { ... } lock_t; void lock(lock_t *lk); // Critical Section void unlock(lock_t *lk);
void spin_lock(lock_t *lk) { retry: int got = atomic_xchg(&lk->status, ); if (got != ) { goto retry; } } void spin_unlock(lock_t *lk) { atomic_xchg(&lk->status, ); }