This preview shows page 1. Sign up to view the full content.
Unformatted text preview: eger ID. Outline a different approach that does not call the malloc or free functions. B. What are the advantages and disadvantages of this approach? 11.7.2 Deadlocks
Semaphores introduce the potential for a nasty kind of runtime error, called deadlock, where a collection of threads are blocked, waiting for a condition that will never be true. The progress graph is an invaluable tool for understanding deadlock. For example, Figure 11.32 shows the progress graph for a pair of threads that use two semaphores for sharing. From this graph, we can glean some important insights about deadlock:
Thread 2 V(s) ... V(t) ...
deadlock state A trajectory that does not deadlock ... Forbidden region for s P(s) ... P(t) Initially s=1 t=1 ... ... d Forbidden region for t Deadlock region A trajectory that deadlocks
P(s) ... P(t) ... V(s) ... V(t) Thread 1 Figure 11.32: Progress graph for a program that can deadlock. 600 CHAPTER 11. CONCURRENT PROGRAMMING WITH THREADS ¯ The programmer has incorrectly ordered the È and Î operation...
View Full Document
- Spring '10
- The American