CS4410- hw2-soln - CS4410 - Fall 2008 Homework 2 Solution...

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

View Full Document Right Arrow Icon
CS4410 - Fall 2008 Homework 2 Solution Due September 23, 11:59PM Q1. Explain what goes wrong in the following version of Dekker’s Algorithm: CSEnter(int i) { inside[i] = true; while(inside[j]) { inside[i] = false; while(turn == j) continue; inside[i] = true; } } CSExit(int i) { turn = j; inside[i] = false; } Answer: There is a possibility of starvation here. Suppose process j is in critical section and process i is busy waiting at the inner while loop. Now when process j exits the critical section it sets turn = i, but it immediately tried to access the critical section and so sets inside[j] = true. Right before process j executes “while (inside[i])”, scheduler schedules process i. Now process i exits from the inner while loop as turn = = i now, but it finds inside[j] to be true so continue the outer while loop. Then after it executes “inside[i]=false”, the scheduler schedules process j and it finds the condition at outer while loop to be false and enters the critical section. As a result, process i busy waits at outer while loop. These steps can repeat arbitrary number of times and that starves process i and it may never enter the critical section. In the original algorithm, there is an extra checking “if (turn==j)” which ensures that this starvation never happens. Grading guide: -5 : Failing to mention starvation / violation of bounded waiting; mentioning it violates mutual exclusion (two threads inside the critical section simultaneously) which actually does not happen here. -1 : Mentioning starvation, but no explanation how it happens -5 : Just mentioning it does not have "if (turn==j)", but no explanation on why it is wrong (i.e., starvation/violation of bounded waiting)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Q2. Round-robin schedulers normally maintain a list of all runnable processes, with each
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.

This note was uploaded on 10/02/2008 for the course CS 4410 taught by Professor Vollset during the Fall '07 term at Cornell University (Engineering School).

Page1 / 5

CS4410- hw2-soln - CS4410 - Fall 2008 Homework 2 Solution...

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