0
$\begingroup$

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

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

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ okay ,but what happens when b comes again and again ? i.e a new instance of thread B. $\endgroup$
    – Ramkumar
    Feb 15, 2014 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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