3 ms·
Thanks, why do you need to spin if there is no contention for the lock though? That sounds counterintuitive.
by bogomipz 9y ago
Thanks, why do you need to spin if there is no contention for the lock though? That sounds counterintuitive.
- slrz 9y agoWell, you don't. Just like when acquiring an unlocked spinlock. ;-) Should look something like this: for(;;){ if(atomic_swap(&thefutex, 1) == 0) break; // we own the lock now // slow path, go to sleep until awoken syscall(SYS_FUTEX, FUTEX_WAIT, ...); }