Waiting for the Hardware to Finish
When your driver asks a device to do something slow, the calling thread should sleep rather than spin, and be woken when the interrupt arrives. A completion is the one-shot version of that: one side waits, the other signals done. A condition variable is the general version: a thread sleeps while holding a lock, the lock is released while it waits, and it re-checks its condition when woken. Both replace the C pattern of a hand-rolled wait queue plus a flag, where the classic bug is missing the wake-up because it happened between your check and your sleep.
Questions this Concept answers
- Why does waiting on a condition variable release the lock the waiter was holding?
Completion Synchronization for Linux Kernel Threads
Completion synchronization is a Linux kernel primitive for signaling between threads: one thread performs work and calls a "wake" operation, while another sleeps efficiently (rather than spinning or …