a3sp06solutions - CS 414 Assignment 3 Solutions 10 points...

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

View Full Document Right Arrow Icon
10 points per answer for 1, 4a-c, 6a-b, 15 points per answer for 2a-b and 30 points each for questions 3, 5 (150 max). Due Wednesday February 22. Short-answer questions (just a sentence or two each,please). 1. In class, we saw that an atomic test and set operation can be used to implement critical sections on a machine supporting parallelism (with multiple physical CPUs). But suppose that you were given a different atomic instruction called decrement . This instruction decrements a variable and leaves the initial value in register 0. Could decrement be used to implement critical sections? Show us how or explain why not. Solution Yes. We can try and mimic test and set with decrement. free = 1; (initially) CSEnter: while(decrement(free) < =0) { continue; } CSExit: free= 1; This gives us mutual exclusion and progress. We can extend this solution using similar constructs as we did in test and set (the waiting[] variables), to ensure bounded waiting. Comments Many students gave solutions assuming atomic clear(). It is possible to have bakery style algorithms without any atomic instructions. If we use busy waiting like in the solution above, there is an overflow problem since the value of free could overflow and wrap back to 0. 2. Consider the N-process Bakery Algorithm: CSEnter(i): chosing[i] = true; number[i] = max(number[0], . .., number[N-1])+1; chosing[i] = false; for(j = 0; j < N; j++) { while(chosing[j]) continue; while(number[j] > < (number[i],i)) continue; } CSExit(i): number[i] = 0; (a) Suppose that process 2 is trying to enter the critical section and has already picked a number value and set chosing[2] to false. . In a ”worst case scenario”, how many times could process 0 ”sneak in” before process 2 gets its turn? Explain. Solution The following solution interprets “sneaking in” as “getting to enter the Critical Section”. If it is interpreted as “entering CSEnter and then getting to enter the Critical Section”, the answers would change(reduce by 1 each). Since this is a worst-case scenario, assume process 0 (P0) has a lower id than does process 2 (P2). If P0 is now inside CSEnter, and has already picked up a lower number(or the same number), P0 would get to go before P2. In any other case, P2 gets to go earlier. So the answer here is 1. 1
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 / 5

a3sp06solutions - CS 414 Assignment 3 Solutions 10 points...

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