

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


OS comps 10 ā 11:30am, 4140 CSE bldg. October 1, 2007 Answer each of the four numbered questions in a separate blue book.
int in0 = 0 , in1 = 0 ; int turn = 0 ;
/* process 0 */
while ( 1 ) { in0 = 1 ; turn = 1 ; while ( in1 && turn == 1 ) ; /* critical section */ in0 = 0 ; }
/* process 1 */
while ( 1 ) { in1 = 1 ; turn = 0 ; while ( in0 && turn == 0 ) ; /* critical section */ in1 = 0 ; } a. You are explaining Petersonās algorithm to a friend, who observes āThis is crazy. The variable turn indicates which process enters the critical section when both wish to enter. Why should process 0 want process 1 to enter? Process 0 should want to enter first! So, process 0 should set turn to 0 (and process 1 should enter turn = 1)ā. Is this a good idea? Explain. b. Some multiporcessors do not have atomic memory operations. For example, many architectures locally cache writes until a memory barrier instruction is executed. This works as follows: suppose (shared memory) address 100 contains the value 13. If processor A writes 25 to address 100, the value will be cached at A until processor A issues a memory barrier instruction. The memory barrier instruction forces the cached value back to shared memory. Petersonās algorithm, as written above, has no memory barrier instructions. Does it correctly implement mutual exclusion on a multiprocessor without them? Explain. If it doesnāt, then insert the fewest memory barrier instructions that will make it a correct implementation and explain why your solution is correct and minimal. You may assume that the operating system scheduler executes a memory barrier instruction immediately before preempting a process from a processor.