


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



COMP 310, Operating Systems, Fall, 2004 Exam 1 November 3, 2004 This exam is closed book, closed notes. Please write all your answers and show all your work in the blue book provided.
void Condition::Wait( Lock *l ) { ASSERT( conditionLock -> isHeldByCurrentThread() );
queue->Append((void*)currentThread); conditionLock->Release(); currentThread->Sleep(); conditionLock->Acquire(); }
The problem occurs when the thread (call it T1) is interrupted AFTER is releases the condition lock but BEFORE it goes to sleep. In this case, another thread may come along and signal the CV, thus taking T1 off the conditionLock queue and putting it on the ready queue. However, it is still on the ready queue (that’s where it went when it got interrupted), so nothing will happen. When T1 runs again it will immediately go to sleep, but now it is no longer on the CV queue, nor is it on the ready queue, thus it is lost forever. This is the only way I can see that the thread will get lost forever.
Semaphore *s = new Semaphore( 1 );
Lock::Acquire() { s->P(); }
Lock::Release() { s->V(); }
// Global variables Lock* mutex = new Lock(); Condition* hold = new Condition(); int turn = 0;