Cmclcscmuedu in the simplest case there is a one to

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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 fix the deadlock? 11.8 Summary Threads are a popular and useful tool for introducing concurrency in programs. Threads are typically more efficient 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 difficult 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

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online