Week 6 - CST 334

 This week we learned about condition variables and how they are used to let threads sleep more efficiently. Specifically, wait() and signal() are used to released the lock and and signal a thread to wake up and start spinning. We also learned about semaphores which are synchronization primitives used to control access to shared resources in concurrent programming. A thread can be blocked or woken up by decreasing or increasing the integer value of the semaphore. The value dictates what the thread will do: a negative value will block the thread and increasing it will wake up another. In a binary semaphore, the value is either 0 or 1, which is used to ensure mutual exclusion so only one thread has access to resources. A counting semaphore has a value that is at least 0 or higher. This allows multiple threads to access a resource at a time. In a bounded buffer, producers put threads in while consumers take them out. We also learned about the possibility of deadlocks, where multiple threads wait forever for the other to release a lock. The four conditions that must occur for there to be deadlock: Mutual exclusion where only one thread can use a resource at a time; hold and wait where a thread is holding a resource and waiting while another thread waits for the resource that is being held; no preemption where resources can only be given up voluntarily; circular wait where each thread is holding a resource that the next is waiting on. 

Comments