This preview shows page 1. Sign up to view the full content.
Unformatted text preview: e error is often not repeatable because different executions have different trajectories. Practice Problem 11.7:
Consider the following program, which uses a pair of semaphores for sharing. Initially: s = 1, t = 0. Thread 1: P(s); V(s); P(t); V(t); Thread 2: P(s); V(s); P(t); V(t); ¯ ¯ A. Does the program always deadlock? B. What simple change to the initial semaphore values will ﬁx the deadlock? 11.8 Summary
Threads are a popular and useful tool for introducing concurrency in programs. Threads are typically more efﬁcient than processes, and it is much easier to share data between threads than between processes. However, the ease of sharing introduces the possibility of synchronization errors that are difﬁcult to diagnose. Programmers writing threaded programs must be careful to protect shared data with the appropriate synchronization mechanisms. Functions called by threads must be thread-safe. Races and deadlocks must be avoided. In sum, the wise programmer approaches the design of threaded programs with great care and not a little trepidation. 11.8. SUMMARY 601...
View Full Document