a spin lock solution to the critical path problem is shown below . my question is will this or will this not result in starvation ?

    Thread A                Thread B
leave note A;           leave note B;
while (note B) {\\X     if (noNote A) {\\Y
    do nothing;             if (noMilk) { 
}                               buy milk;

if (noMilk) {                  }
    buy milk;           }
}                       remove note B;
remove note A;

let me illustrate my point ,if thread A and B are scheduled as shown wont that result in starvation ?

sync issue

note : those arrows are meant to indicate a cycle .

note: I'm following the online operating system course from Berkeley (http://www.youtube.com/playlist?list=PL-XXv-cvA_iCrnl0625nXp4GimjT-cv_1) .

In lecture 4 ,they talk about this as a correct solution to the critical path problem

  • $\begingroup$ Sorry .I'll re-edit the question to add the contents from the slide. $\endgroup$ – Ramkumar Feb 16 '14 at 15:24

Process B isn't looping; it runs and then quits. In other words, there won't be a second "leave note B" in your picture. There is a loop in process A (a busy wait, as it's called) and when process B removes its note, then execution will return to A's loop: A will check and see that there is milk so will remove its note and quit.

| cite | improve this answer | |
  • $\begingroup$ okay ,but what happens when b comes again and again ? i.e a new instance of thread B. $\endgroup$ – Ramkumar Feb 15 '14 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.