While taking this exam, you may use books, computers, the Internet, your own brain, and any divine guidance which may be available to you. You may, in addition, ask Jeff Ondich questions and expect at least a cordial "I can't tell you that." Otherwise, don't talk to other people about the content of the exam.
Have fun.
// Shared global variable, initialized to 0. int lock = 0; void EnterCriticalRegion( void ) { while( lock == 1 ) { lock = 1; } lock = 1; } void LeaveCriticalRegion( void ) { lock = 0; }The next morning, Zoe, having had a full night's sleep, read Elmo's code. The orange fur was flying as Zoe ran to Elmo's cubicle, poured out all his remaining cans of Mountain Dew, woke him up, sent him home, signed him up for a software engineering workshop, and sent him e-mail telling him that if he ever held another all-night coding session, he could start looking for a new job.
When Elmo returned from the workshop a few days later, he found a hard copy of his code taped to his monitor, with a hand-written note from Zoe saying "Busy waiting, races, deadlock, and starvation, all in 16 lines of code (including blank lines and comments). Brilliant!"
Explain how Elmo's code can lead to race conditions, deadlock,
and starvation. That is, list a possible (and, preferably,
plausible) sequence of events that would cause a race
condition. Then do
the same for deadlock and starvation.