hw5 - CSE 422S (Fall 2009) Operating Systems Organization...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: CSE 422S (Fall 2009) Operating Systems Organization Homework 5 Reading: Tannenbaum, Sections 2.3, 2.5 Due: Wed, Nov. 4, 2009 Problem 1 (2 Points) Consider the following parallel program: int X = 0; // Global (shared) int want[10] = {0, ... , 0}; // Global (shared) void sum() { for (int n=0; n < 10; n++) if ( ! want[n]) { X += n; want[n] = 1; } } void main() { X=0; parbegin sum(); sum(); parend; print(X); } The construct parbegin S1; S2; ... parend with statements S1, S2, ... means that the statements can execute in parallel subject to any synchronization. Determine the smallest value of the shared variable X that will be printed and explain how you arrived at this answer. Assume: 1) processes can execute at any relative speed; 2) a value can be incremented/decremented after it has been loaded into a register; and 3) the values of X and want[n] are loaded only once for each execution of the loop. Problem 2 (0 Points) This problem considers Petersons 2-process algorithm given in class. a) Explain how the algorithm prevents one process from monopolizing the critical section; i.e., prevent starvation? b) Explain how the algorithm guarantees freedom from deadlock? Problem 3 (6 Points) The following is a software-only mutual exclusion algorithm for two processes (id = 0 and 1): 1 boolean blocked[2] = { 0, 0 }; 2 int who = 0; 3 void P (int id) { 4 while (TRUE) { 5 blocked[id] = TRUE; 6 while (who != id) { while (blocked[1-id]) who = id; } 7 // ... some critical section is here ... 8 blocked[id] = FALSE; // exit section 9 } 10 } 11 void main () { parbegin P(0); P(1); parend; } 1 a) If the processes execute at the same rate as much as possible, in what order will the processes enter the critical section....
View Full Document

Page1 / 4

hw5 - CSE 422S (Fall 2009) Operating Systems Organization...

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