prac7-fall09

# prac7-fall09 - CMSC330 Fall 2009 Practice Problems 7 1....

This preview shows pages 1–3. Sign up to view the full content.

CMSC330 Fall 2009 Practice Problems 7 1. Multithreading, Data Races, and Deadlock a. For the following program, give two schedules under which the final value of i differs in the two schedules. Give the schedule as a list of line numbers, and in each case, also give the final value of i. l = new ReentrantLock(); m = new ReentrantLock(); i = 0 Thread 1 1. l.lock(); 2. i = 3; 3. l.unlock(); Thread 2 4. m.lock(); 5. i = i + 1; 6. m.unlock(); b. For the following program, give one schedule under which there will be a deadlock, and give one schedule under which there will not be a deadlock. Give the schedule as a list of line numbers. l = new ReentrantLock(); m = new ReentrantLock(); n = new ReentrantLock(); Thread 1 1. l.lock(); 2. m.lock(); 3. m.unlock(); 4. l.unlock(); Thread 2 5. m.lock(); 6. n.lock(); 7. n.unlock(); 8. m.unlock(); Thread 3 9. n.lock(); 10. l.lock(); 11. l.unlock(); 12. n.unlock();

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
c. Using language notation similar to above, write a program that has no data races, but
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/13/2012 for the course CMSC 330 taught by Professor Staff during the Fall '08 term at Maryland.

### Page1 / 3

prac7-fall09 - CMSC330 Fall 2009 Practice Problems 7 1....

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online