cs162_fa08_mt1-9

cs162_fa08_mt1-9 - simultaneous Enqueue and Dequeue...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 162 Fall 2008 Midterm Exam I October 15, 2008 Page 11/21 Problem 3e[3pts]: For each of the following potential context switch points, state whether or not a context switch at that point could cause incorrect behavior of Enqueue(); Explain! void Enqueue(Object newobject) { 1 QueueEntry newEntry = new QueueEntry(newobject); 2 QueueEntry oldtail = tail; 3 tail = newEntry; oldtail.next = newEntry; } Point 1: Point 2: Point 3: Problem 3f[4pts]: Rewrite code for Enqueue() , using the CAS() operation, such that it will work for any number of
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: simultaneous Enqueue and Dequeue operations. You should never need to busy wait. Do not use locking (i.e. don’t use a test-and-set lock). The solution is tricky but can be done in a few lines. We will be grading on conciseness. Do not use more than one CAS() or more than 10 lines total (including the function declaration at the beginning). Hint: wrap a do-while around vulnerable parts of the code identified above. void Enqueue(Object newobject) { QueueEntry newEntry = new QueueEntry(newobject); // Insert code here }...
View Full Document

{[ snackBarMessage ]}

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