Deadlocks and Monitors
Image by Dean Moriarty from Pixabay
In this module, we will learn about another common concurrency bug, deadlock, and we will learn how to best manage synchronization in userland.
Learning Objectives
We've learned about the process, threads of control, multi-threaded processes, race conditions, locks, and semaphores. Here, we'll begin to understand the inherent danger in semaphores as we learn about deadlock, the conditions for deadlock, and how to manage synchronization in application code.
Upon completion of this module, you will be able to:
- Explain deadlock, the four conditions of deadlock, and why they are necessary and sufficient
- Evaluate code to determine if there is a potential for deadlock
- Control threads using monitors so that desired behavior is ensured
- Prevent concurrency bugs, such as deadlocks and race conditions, through the proper use of locks, semaphores, and monitors
- Describe the need for advanced synchronization techniques and how to use them safely
Learning
- Video: The Philosophers (2 minutes)
- Video: Deadlock (12 minutes)
- Video: Monitors (6 minutes)
- Video: Condition Variables (5 minutes)
- Video: Resource Variables and Signal Semantics (15 minutes)
-
Slides that were presented in the videos
Note that these videos have embedded formative assessments---you'll want to watch the videos and complete those before class, so that you can earn participation credit.
Recommended Readings
Completing the readings in this class is highly recommended---it can be very helpful to see how the concepts are explained by a different person, and the extra details can help the pieces fit together.
OSTEP: Common Concurrency Problems, pages 1-11 (stop at "Deadlock Avoidance via Scheduling")
OSTEP: Monitors
Fun Insights
- An example of lock ordering from the Linux kernel (begins on line 70)
- Note that this example is NOT using monitors.
- Producers and Consumers using monitors
From Class
Evaluating Your Understanding
We are providing these rubrics for each module so that you can better understand what is expected and evaluate your understanding against those expectations. The hope is that, if you find yourself earning a 3 or below, you will continue to enhance your understanding until you find yourself earning a 4 or a 5.
| Standards | 5 | 4 | 3 | 2 |
|---|---|---|---|---|
| Controlling Threads | Student accurately explains the purpose and actions of concurrency control mechanisms and accurately demonstrates their use on example problems. | Student satisfactorily explains the purpose and actions of concurrency control mechanisms and accurately demonstrates their use on example problems. | Student unsatisfactorily explains the purpose and actions of concurrency control mechanisms, but satisfactorily demonstrates their use on example problems. | Student does not submit the work OR student unsatisfactorily explains the purpose and actions of concurrency control mechanisms and unsatisfactorily demonstrates their use on example problems. |
| Concurrency Bugs | Student accurately explains how concurrency bugs may occur in the code and accurately describes how to prevent them. Student accurately identifies the conditions of deadlock and can accurately explain why they are necessary and sufficient. | Student satisfactorily explains how concurrency bugs may occur in the code and accurately describes how to prevent them. Student accurately identifies the conditions of deadlock and can satisfactorily explain why they are necessary and sufficient. | Student satisfactorily explains how concurrency bugs may occur in the code and satisfactorily describes how to prevent them, but student unsatisfactorily identifies the conditions of deadlock and unsatisfactorily explains why they are necessary and sufficient. | Student does not submit the work OR unsatisfactorily explains how concurrency bugs may occur in the code and unsatisfactorily describes how to prevent them, and student unsatisfactorily identifies the conditions of deadlock and unsatisfactorily explains why they are necessary and sufficient. |
| Short Answer Questions: Concurrency-Specific | Student submitted answers to given questions that accurately and succinctly answer the questions. | Student submitted answers to given questions that satisfactorily and succinctly answer the questions. | Student submitted answers to given questions that unsatisfactorily answer the questions. | Student does not submit the answers OR submitted answers to given questions that incorrectly answer the questions. |
| Short Answer Questions: Concurrency in the larger system | Student submitted answers to given questions that accurately and succinctly answer the questions. | Student submitted answers to given questions that satisfactorily and succinctly answer the questions. | Student submitted answers to given questions that unsatisfactorily answer the questions. | Student does not submit the answers OR submitted answers to given questions that incorrectly answer the questions. |