CST 334 - Learning Journal week 6
How Semaphores Work:
Semaphores are synchronization tools that control access to shared resources in a concurrent environment. A semaphore holds an integer value that represents the number of permits available. Process or threads can perform two main operations, wait - which decreases the semaphore and may block the thread if no permits are available, and signal - which increases the semaphore and potentially unblocks a waiting thread. Semaphores are coordinators, the coordinations prevents conflicts, race conditions and incorrect program behavior.
Pros and Cons of Semaphores vs. Other Synchronization Tools:
Comparison of semaphores to other tools such as mutexes, condition variables and monitors -
Semaphores are flexible - they can enforce mutual exclusion and general resource counting which mutexes cannot, but semaphores can also be error-prone, because the programmer is responsible for correct ordering. Monitors encapsulate locking behavior into the language or library, reducing opportunities for mislabels. Condition variables allow waiting on specific conditions rather than on resource counts, which can be more intuitive.
Least - Understood Topics:
The hardest part for me to describe was the conceptual difference between semaphores and monitors/condition variables, especially understanding when I should prefer one over the other. I understand that they solve different categories of synchronization problems, but I sometimes struggle to articulate why a monitor might make a problem easier or safer than using a semaphore directly. For the semaphore vs. monitor comparison: I understand the rules (semaphores rely on integer counts; monitors automatically handle locking), but I’m still unclear about how these differences actually change the process of designing a concurrent system.
Aha Moments:
Understanding the concept of counting semaphores. Binary semaphores felt straightforward, but counting semaphores initially seemed abstract. The moment it clicked was when I realized that a counting semaphore essentially models a pool of identical resources.
Questions About What Comes Next:
- How do OS schedulers interact with synchronization primitives?
- How do different operating systems (Linux, Windows, MacOS) implement semaphores internally?
Comments
Post a Comment