2 ms·
With a mutex, counter and condition variable you can trivially implement a semaphore and be sure that it's correct at a glance. Implementing a mutex and condit
by kazinator 4y ago
With a mutex, counter and condition variable you can trivially implement a semaphore and be sure that it's correct at a glance.
Implementing a mutex and condition variable with semaphores is an exercise in Rube Goldberg mousetrap construction.
Semaphores aren't go to because they are lower level building blocks; only in the sense that it's hard to convince yourself that a semaphore-based program is correct.
The premise in this article is false. Linux was never heavily based on semaphores. The main synchronization workhorse in Linux are spinlocks, and the wait queue mechanism: and always have been. Well, spinlocks since SMP was introduced in 1.3; before that, interrupt disabling and enabling.
Wait queues are a close cousin of condition variables.