Operating Systems: Week 6
During this week, we have learned about several objectives, including condition variables, semaphores, and common concurrency problems. A condition variable is an explicit queue where threads are able to wait for a condition and then signal other threads when the condition might be true. Condition variables work in company with mutex to help stay away from race conditions. I have learned through the readings as well as the many detailed examples given in the videos provided to us by the professor. Here are examples of condition variable usage: pthread_cond_wait(cond, lock), pthread_cond_signal(cond), and pthread_cond_broadcast(cond). An important part of condition variables is to use while loops and not an if statement. The reason for this is that if we use an if statement, we can cause the condition to change while the thread is asleep; while loops are a safer option.
I also learned about semaphores and how a semaphore can be tricky to work with, but can also help coordinate access to shared resources using multiple threads. A semaphore is an integer that can be any value that can perform a signal operation or a wait operation.
Additionally, I have learned about types of concurrency bugs and how to prevent or fix them. A few bugs that we can encounter are deadlocks and non-deadlock bugs. A deadlock bug is when either two or more threads keep waiting on each other to release resources, but no one can proceed. There are four conditions for deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. There are three ways we can help with deadlock bugs: prevention, avoidance, and detection/recovery.
Comments
Post a Comment