cs162_fa08_mt1-9 - simultaneous Enqueue and Dequeue...

Info iconThis 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
Background 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

This note was uploaded on 08/26/2009 for the course CS 162 taught by Professor Kubiatowicz during the Spring '02 term at Berkeley.

Ask a homework question - tutors are online