Week 6

 Through studying thread synchronization primitives, I learned that semaphores are fundamental tools for coordinating access between processes and threads. A semaphore maintains an integer counter that determines resource availability - when used as a lock, the first process to acquire it sets the count to 0, effectively claiming the resource and blocking others until release. Semaphores are versatile synchronization mechanisms that can be initialized to values higher than 1 to control access to multiple instances of a resource, and when initialized to 1, they function effectively as binary locks. I also discovered that kernel-level threads can successfully use kernel semaphores for synchronization since they operate directly under kernel management, giving them access to kernel synchronization primitives.

The study of classic synchronization problems revealed important principles about deadlock prevention and barrier implementation. In the dining philosophers problem, I learned that naive approaches like having each philosopher pick up their own numbered chopstick first actually creates deadlock rather than preventing it, as this leads to circular waiting. For synchronization barriers, I discovered that typically only 2 semaphores are needed - one to count arriving threads and another to signal when all can proceed. Importantly, I learned that barriers can be implemented using either semaphores or condition variables with locks, dispelling the misconception that only semaphores are capable of solving barrier synchronization problems.

The Anderson/Dahlin methodology provided a systematic approach to converting regular classes into thread-safe implementations through a structured 6-step process: starting with a lock, adding condition variables, preparing the class for threading, implementing proper lock/unlock patterns, adding signal/broadcast calls, and finally incorporating wait loops with proper condition checking. When comparing threads to processes, I learned that threads offer significant advantages in startup time, context switching overhead, and memory sharing ease due to their shared address space. However, this shared memory also introduces disadvantages like reduced memory safety and increased susceptibility to race conditions, highlighting the trade-offs inherent in different concurrency models.

Comments

Popular Posts