

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
Material Type: Exam; Professor: Berger; Class: Operating Systems; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Fall 2005;
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


CMPSCI 377 Operating Systems Fall 2005
Lecturer: Emery Berger Scribe: Rob Tate, Lou Karadashkov
Today:
Atomic instructions are provided by the architecture. -Cannot be interrupted -Needed to build locks -Test and Set (most architectures) -Exchange(x86) -LLSC–Load Link Store Condition(PowerPC)
Example(this must be atomically provided by architecture):
int testset (int value) { int old = value; value = 1; return old; }
To acquire, spin in a while loop, like “while(testset(value)){” To release, set value back to 0 -Busy-Loops are bad news. -“Priority Inversion” -High priority threads might get the lock, but they should always get it before lower priorities -Will actually work Locks should be optimized for the common case, that they are uncontended.
7-2 Lecture 7: October 11
Let’s use a queue:
void acquire(){ while(true){ if (testset(value)){ put thread on queue go to sleep }else{ break; } } }
void release(){ value = 0; wake up threads }
How many threads to wake up? -If we wake up only one, we might get Priority Inversion -If we wake them all up, we might get “Thundering Herd” -We should use a priority queue and wake up the one at the front
Provides Mutual Exclusion, but... -Deadlock can easily happen. -Someone can forget to unlock. -Someone can try to lock twice.
What if we want to let two people access but not three? Can’t do this with locks. We need Semaphores!
Semaphores are basically non-negative integer counters with atomic methods for incrementing and decre- menting. These methods are used to make wait and signal methods.
-wait() decreases semaphore by one unless it is zero, in which case it goes on queue -also called P() -signal() increases semaphore by one and wakes up thread(s) -also called V()