prac7-soln-fall09

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

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

CMSC330 Fall 2009 Practice Problems 7 Solutions 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(); Since l and m are different locks, they do not provide any mutual exclusion in this example, and the threads may be interleaved arbitrarily. Some example solutions: 1, 2, 3, 4, 5, 6 - i = 4 1, 4, 5, 2, 3, 6 - i = 3

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

View Full Document
c. Using

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

View Full Document
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 / 6

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

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

View Full Document
Ask a homework question - tutors are online