hw05Solutions

hw05Solutions - CS 411 Operating Systems II Homework...

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

View Full Document Right Arrow Icon
Page 1 of 4 CS 411 Operating Systems II Spring 2009 Homework Assignment #5 Solutions 1. Following is an algorithm for solving the critical section problem. Does this solve the problem of mutual exclusion? If so, prove it. If not, give an example that disproves it. Shared boolean variables are initialized:. Shared data initialization: inT1 = inT2 = false Process1 Process2 while(1){ while(inT2) ; //do nothing inT1 = true; // critical section inT1 = false; // remainder section while(1){ while(inT1) ; //do nothing inT2 = true; // critical section inT2 = false; // remainder section Answer: It does NOT solve the problem. Several counter-examples are possible, e.g., if Process1 starts first, it tests inT2 . If Process2 preempts before Process1 can set inT1 = true, then both processes can be in their critical sections simultaneously. 2. Suppose that synchronization is implemented using monitors. o Why must a process wait outside a monitor for a resource? Answer: If a process waits inside the monitor, no other processes can enter the monitor (mutual exclusion), so the resource can not be released by any process that holds it. This could cause all processes waiting for the resource to deadlock. o Describe the structure of a Java condition variable Answer: A condition variable has a queue as its instance data, and has two methods: wait () and signal () .
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

hw05Solutions - CS 411 Operating Systems II Homework...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online