prac7-fall09

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

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

View Full Document Right Arrow Icon
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();
Background image of page 1

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

View Full Document Right Arrow Icon
c. Using language notation similar to above, write a program that has no data races, but
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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 Right Arrow Icon
Ask a homework question - tutors are online