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

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

View Full Document Right Arrow Icon
CS 414 Assignment 3 Solutions 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] > 0 && (number[j],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.
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

0/0 PREVIEWS LEFT
Sign up to access 24/7 study resources for your classes

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern