Assignment3Soln

Assignment3Soln - Assignment 3 Solutions Two process mutual...

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

View Full Document Right Arrow Icon
Assignment 3 Solutions
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Two process mutual exclusion Protocol 4: shared data: boolean flag[2]; //initial values false int turn; // 0 or 1 Process i: 1 while (true) ...... // ENTRY PROTOCOL 2 j = ( i + 1 ) % 2; 3 flag[ i] = true; 4 while ( flag[ j ] ) { 5 if ( turn == j ) { 6 flag[ i ] = false ; // reset my own request flag - backoff 7 while ( turn == j ) ; // busy wait 8 flag[ i ] = true; } } // EXECUTE CRITICAL SECTION // EXIT PROTOCOL 9 flag[i] = false; 10 turn = j; // set turn to the other ..... } //end of while(true)
Background image of page 2
Answer In Protocol 4, one process may repeatedly enter the critical section while the other process is blocked waiting in the entry section. Suppose that Process 0 is in the CS. Process 1 is busy waiting in 7. Process 0 leaves CS; executes steps 9 and 10 Process 1 exits step 7, but before it executes step 8, context switch occurs. Process 0 goes once again executes steps 2, 3, and 4; and it enters the critical section because flag[1] is still false.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Peterson’s Protocol Protocol 5 shared data: boolean flag[2]; int turn; // 0 or 1 Process i: while ( true ) { ...... // ENTRY PROTOCOL j = ( i + 1 ) % 2; flag[ i ] = true; turn = j; // set turn to the other while ( flag[ j ] && ( turn == j ) ) ; // busy wait // EXECUTE CRITICAL SECTION // EXIT PROTOCOL flag[i] = false; .....
Background image of page 4
Answer In Protocol 5, does not have such a problem. If two process are competing, the will enter CS one after another. No process gets a chance to enter the CS two consecutive times
Background image of page 5

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

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

This note was uploaded on 03/06/2012 for the course CSCI 5103 taught by Professor Staff during the Fall '08 term at Minnesota.

Page1 / 17

Assignment3Soln - Assignment 3 Solutions Two process mutual...

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

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