Presentation is loading. Please wait.

Presentation is loading. Please wait.

Solutions of a Problem in Concurrent Programming - Yang Le 1 Solutions of a Problem in Concurrent Programming Proseminar Software Pioneers By Prof. Dr.

Similar presentations


Presentation on theme: "Solutions of a Problem in Concurrent Programming - Yang Le 1 Solutions of a Problem in Concurrent Programming Proseminar Software Pioneers By Prof. Dr."— Presentation transcript:

1 Solutions of a Problem in Concurrent Programming - Yang Le 1 Solutions of a Problem in Concurrent Programming Proseminar Software Pioneers By Prof. Dr. Heike Wehrheim Diplo. Inform. Björn Metzler

2 Solutions of a Problem in Concurrent Programming - Yang Le 2 Contents A brief introduction of Dijkstra and Lamport Problem in Concurrent Programming Dijkstra’s Solution Semaphores Solution Lamport’s Solution Conclusion

3 Solutions of a Problem in Concurrent Programming - Yang Le 3 Edsger W. Dijkstra and Leslie Lamport Photographs are from google photo

4 Solutions of a Problem in Concurrent Programming - Yang Le 4 Problem in Concurrent Programming N computers one “critical section”. Two requirements: Communication between computers Undividable writing or reading Critical Section 4 1 2 3 5 N

5 Solutions of a Problem in Concurrent Programming - Yang Le 5 Basic Goals of Dijkstra’s Solution Symmetric between N computers No “After you” – “After you” – blocking i Please, you can go first. j No, no. I will wait after you.

6 Solutions of a Problem in Concurrent Programming - Yang Le 6 Dijkstra’s Solution Code from “Solution of a Problem in Concurrent Programming Control” – E.W.Dijkstra Part I: Interger j; Li0:b[i]:=false; Li1:if k≠i then Li2: begin c[i]:=true; Li3: if b[k] then k:=i; goto Li1; end else. 123N Critical Section i 123iNk b[i]TTTFT c[i]TTTTTi

7 Solutions of a Problem in Concurrent Programming - Yang Le 7 Dijkstra’s Solution Part II: Li4:begin c[i]:=false; for j:=1 step 1 until N do if j≠i and not c[j] then goto Li1 end; critical section; c[i]:=true;b[i]:=true;. go to Li0 123N Critical Section i 123iNk b[i]TTTFT c[i]TTTFTi Code from “Solution of a Problem in Concurrent Programming Control” – E.W.Dijkstra

8 Solutions of a Problem in Concurrent Programming - Yang Le 8 Problems in Dijkstra’s Solution When the i-th computer breaks down in the critical section, the whole system will be in a dead lock 123N Critical Section i What is he doing for such a long time? Who knows. Just have to wait here. ??? ? Hey, we have waited too long!

9 Solutions of a Problem in Concurrent Programming - Yang Le 9 Semaphores Solution Semaphore values Two “indivisible actions” P- operation V- operation Random choosing from the waiting list begin semaphore mutex; mutex := 1; parbegin begin L1: P(mutex); critcal section 1; V(mutex); remainder of cycle 1; go to L1 end; begin L2: P(mutex); critical section 2; V(mutex); remainder of cycle 2; go to L2 end; parendend end

10 Solutions of a Problem in Concurrent Programming - Yang Le 10 Problems of Semaphores Solution We can no forecast or decide which process will be removed from the waiting list. Explicit control - deadlock What is he waiting for? And why make him the boss? i Don’t know. Just wait and see. j Semaphore ?????

11 Solutions of a Problem in Concurrent Programming - Yang Le 11 Lamport’s Solution Begin integer j; L1: choosing[i]:=1; number[i]:=1+maximum(number[1],...number[N]); choosing[i]:=0; for j:=1 step 1 until N do begin L2: if choosing[j]≠0 then goto L2; L3: if number[j]≠0 and (number[j],j)< (number[i],i) then goto L3; end Critical section; Number[i]:=0; Noncritical section; Goto L1; end Critical Section 123Ni 123iN Choosing[]00000 Number[]63425

12 Solutions of a Problem in Concurrent Programming - Yang Le 12 Lamport’s Solution Begin integer j; L1: choosing[i]:=1; number[i]:=1+maximum(number[1],...number[N]); choosing[i]:=0; for j:=1 step 1 until N do begin L2: if choosing[j]≠0 then goto L2; L3: if number[j]≠0 and (number[j],j)< (number[i],i) then goto L3; end Critical section; Number[i]:=0; Noncritical section; Goto L1; end Critical Section 123N i 123iN Choosing[]00000 Number[]63425

13 Solutions of a Problem in Concurrent Programming - Yang Le 13 Problems in Lamport’s Solution These computers are no longer symmetrical. The number attribute will be too big. Critical Section Let’s compare our “number” attribute, then decide who goes to first. i No, I can’t. This is too big to fit in a double integer. j

14 Solutions of a Problem in Concurrent Programming - Yang Le 14 Conclusion Dijkstra’s Solution N computers get equal chances, and avoid “after you” – “after you” – blocking. Weak point: Once one computer breaks down inside the CS, that will be a catastrophe. Semaphores Solution Based on a semaphore value with two undividable action – P and V. Weak point: Too reliance upon a single hardware component. Lamport’s Solution Every computer got its own attribute and don’t afraid “break-down” in CS. This attribute will be too huge and increase the system’s load.


Download ppt "Solutions of a Problem in Concurrent Programming - Yang Le 1 Solutions of a Problem in Concurrent Programming Proseminar Software Pioneers By Prof. Dr."

Similar presentations


Ads by Google