Академический Документы
Профессиональный Документы
Культура Документы
Basic: Program that accepts NTP server as argument, gets and returns time from that server
Three points for well document and tested solution
Problem:
Doesnt prevent starvation Requires checking both neighbors at once
Race condition
Additional properties:
Deadlock free: Eventually someone new gets to eat Lockout free: Eventually every hungry philosopher gets to eat Adversary: One philosopher may try to starve another
Cant just hold the fork indefinitely
No Deterministic Solution
Proof: Assume solution for philosophers 1..n
Philosophers dont know their number!
Probabilistic Solution
Assume Random coin toss
Guaranteed with probability 1 to break symmetry Think trying = true or die While trying s = random(left,right) Wait for fork s then take it If fork ~s available take it else drop fork s Eat drop s=random(left,right) drop fork ~s
If Plato picks up fork infinite number of times, Aristotle finite number, then
P(Plato eats infinite number of times)=1
2. 3.
If deadlocked, every philosopher picks up fork infinite number of times with probability 1 If after t steps, both trying to eat, tried to get same fork. Then with probability u ,
One picks up fork only finite number of times in future, or One gets to eat in next two draws
4.
If at time t the last set of random draws is A, then with probability 1 there is a later configuration B A where two neighbors try to get the same fork first
Theorem: P(Deadlock) = 0
Assume P(Deadlock) > 0
By Lemma 2, if deadlocked everyone performs infinite draws By Lemma 4, with probability 1 there will be infinite sequence of configuration of last draws A0, A1, satisfying condition of Lemma 3 By Lemma 3, n some philosopher eats between An and An+2 with probability 1
Think trying = true; left_signal = right_signal = on s = random(left,right) Wait until s down and (s-neighbor-signal = off or s-last = neutral or s-last = s) then lift fork s If ~s down then lift ~s; trying = false else drop s Eat left-signal = right-signal = off left-last = right; right-last = left Drop forks
Makes proving correctness harder Consider such solutions when building distributed systems!