








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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This lecture is from Operating System Design and Implementation course. Its key words are: Paradise Lost, Lowly Worker Thread, Find Work, Queue Work, Thirda Third Thread, Protected, Happiness Revocation, Summary, Tocttou
Typology: Slides
1 / 14
This page cannot be seen from the preview
Don't miss anything!
Dave Eckhardt Dave Eckhardt Todd Mowry Todd Mowry L11a_Lost
When to use When to use if()if() vs.vs. while()while()
workitem * find_work(void) { workitem *w; mutex_lock(&m); if (going_out_of_business) w = (workitem *) 0; else w = (workitem *) dequeue(q); mutex_unlock(&m); return (w); }
mutex_lock(&m); if (going_out_of_business) w = (workitem *) 0; else { if (!(w = (workitem *) dequeue(q))) { cond_wait(&new_work, &m); w = (workitem *) dequeue(queue); } } mutex_unlock(&m); return (w);
What went wrong? What went wrong?
What went wrong? What went wrong? (^) Nothing!
find_work() queue_work() find_work() lock(&m); if (!..deq(.).) cwait(&new, &m); lock(&m); enqueue(...) csignal(&new); unlock(&m); lock(&m); if (!..deq(.).) unlock(&m); w = deq(.)... return(w); return (0);
What went wrong? What went wrong? (^) Protected world state wasn't ready for us (^) We blocked (^) Somebody prepared the world for us to run (^) We ran (^) We assumed nobody else had run (^) We assumed the world state was still ready for us When have we seen this “happiness revocation”? When have we seen this “happiness revocation”?
if() vs. while() if() vs. while() (^) If somebody can revoke your happiness, you'd better check
(^) This is “just a sub-case of 'TOCTTOU bugs'”, but... (^) Many people think TOCCTOU bugs are always security bugs (^) Fundamentally, we expect the revoked condition to become unrevoked again (soon!) (^) Unlike the general case, this can be fxed in less than a line of code!