4 ms·
I’ve always imagined a lock as a conditional sleeping operation. What’s the difference?
by l33t2328 5y ago
I’ve always imagined a lock as a conditional sleeping operation. What’s the difference?
- dataflow 5y agoI think what the parent was saying was that, for a futex, the kernel wakes you up when the condition might have been satisfied, but spurious wakes are possible too. (I'm counting the simultaneous waking of multiple threads as spurious wakes here.) That's not the case with locks, which only wake up when the condition is satisfied.
- ww520 5y agoLock doesn't have to sleep. The semantic of a lock is that on acquisition it blocks until it's available, and upon unblocking the caller thread has acquired the lock. The blocking can be sleep or be doing busy-spin. Futex is the lower level mechanism to build higher level locks like mutex/semphore/conditional-variable/etc.