






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The cs162 operating systems midterm exam #1 held at the university of california, berkeley in september 1999. The exam covers topics such as threads, thread state transitions, concurrency control, and concurrency problems. Students are required to answer multiple-choice questions and provide solutions to programming problems.
Typology: Exams
1 / 10
This page cannot be seen from the preview
Don't miss anything!







University of California, Berkeley College of Engineering Computer Science Division – EECS
Fall 1999 Anthony D. Joseph
September 29, 1999 CS162 Operating Systems
Your Name:
SID and 162 Login:
TA:
Discussion Section:
General Information: This is a closed book examination. You have two hours to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points given to the question; there are 100 points in all. You should read all of the questions before starting the exam, as some of the questions are substantially more time consuming.
Write all of your answers directly on this paper. Make your answers as concise as possible. If there is something in a question that you believe is open to interpretation, then please ask us about it!
Problem Possible Score 1 12
Total 100
ii)
b. (6 points) List two reasons why threads are useful/important. i)
ii)
The problem statement is as follows: The atomic swap routine pops an item from each of two stacks and pushes the items onto the opposite stack. If either stack does not contain an item, the swap fails and the stacks are left as before the swap was attempted. The swap must appear to occur atomically: there should be no interval of time during which an external thread can determine that an item has been removed from one stack but not yet pushed onto another one. In addition, the implementation must be highly concurrent – it must allow multiple swaps between unrelated stacks to happen in parallel. You may assume that stack1 and stack2 never refer to the same stack.
void AtomicSwap (Stack *stack1, stack2) { Item thing1; / First thing being transferred / Item thing2; / Second thing being transferred */
stack1->lock.Acquire(); thing1 = stack1->Pop(); if (thing1 != NULL) { stack2->lock.Acquire(); thing2 = stack2->Pop(); if (thing2 != NULL) { stack2->Push(thing1); stack1->Push(thing2); stack2->lock.Release(); stack1->lock.Release(); } } }
(Additional space for question 4)
(Additional space for question 5)
No Credit – Problem X: (000000000000 points)
In rural Carbon County, PA, a group of men were drinking beer and discharging firearms from the rear deck of a home owned by Irving Michaels, age 27. The men were firing at a raccoon that was wandering by, but the beer apparently impaired their aim and, despite the estimated 35 shots the group fired, the animal escaped into a 3 foot diameter drainage pipe some 100 feet away from Mr .Michaels’ deck.
Determined to terminate the animal, Mr. Michaels retrieved a can of gasoline and poured some down the pipe, intending to smoke the animal out. After several unsuccessful attempts to ignite the fuel, Michaels emptied the entire 5-gallon fuel can down the pipe and tried to ignite it again, to no avail. Not one to admit defeat by wildlife, the determined Mr. Michaels proceeded to slide feet-first approximately 15 feet down the sloping pipe to toss the match.
The subsequent rapidly expanding fireball propelled Mr. Michaels back the way he had come, although at a much higher rate of speed. He exited the angled pipe “like a Polaris missile leaves a submarine,” according to witness Joseph McFadden, 31. Mr. Michaels was launched directly over his own home, right over the heads of his astonished friends, onto his front lawn. In all, he traveled over 200 feet through the air. “There was a Doppler Effect to his scream as he flew over us,” McFadden reported, “followed by a loud thud.” Amazingly, he suffered only minor injuries. “It was actually pretty cool,” Michaels said, “Like when they shoot someone out of a cannon at the circus. I’d do it again if I was sure I wouldn’t get hurt.”
(This page intentionally left blank)