4 ms·
Why? To me semaphores are the thing you can use to implement a counting producer/consumer thing, a mutex, a critical section, a flag for an interrupt handler.
by zwieback 3y ago
Why? To me semaphores are the thing you can use to implement a counting producer/consumer thing, a mutex, a critical section, a flag for an interrupt handler.
Are you referring specifically to a counting semaphore as opposed to the other things?
- yccs27 3y agoGOTOs are the thing you can use to implement a conditional, a loop, an exception handler.
- zwieback 3y agoI see, so the argument is someone should use semaphores to implement higher-level abstractions that are easier to use? That would make some sense.
- kazinator 3y agoWith 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.