CMSC330 Fall 2009 Quiz #4 Name Discussion Time (circle one): 10am 11am 12pm 1pm 2pm 3pm Instructions • You have 15 minutes for this quiz. • For partial credit, show all of your work and clearly indicate your answers. • Write neatly. Credit cannot be given for illegible answers. 1. (4 pts) Describe one way to ensure a program has no deadlocks. (There are several possible answers) 2. (8 pts) List all possible outputs from the following program. Indicate next to each possible output whether all threads complete at the end, or, if they do not, which threads remain blocked. l = new ReentrantLock(); c = l.newCondition() Thread 1 l.lock(); System.out.print("a "); c.await(); System.out.print("b "); c.signalAll(); System.out.print("c "); l.unlock(); Thread 2 l.lock(); System.out.print("e "); c.signalAll(); System.out.print("f "); c.await(); System.out.print("g "); l.unlock();3. (8 pts) For the following program, give two schedules under which the final value of either i or j 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 and j. l = new ReentrantLock(); m = new ReentrantLock(); i = 0 j = 0 Thread 1 1. l.lock(); 2. i = 3; 3. l.unlock() 4. m.lock(); 5. j = 4; 6. m.unlock(); Thread 2 7. l.lock(); 8. i = 5; 9. j = 6; 10.
View Full Document