Title: Solutions of a Problem in Concurrent Programming
1Solutions of a Problem in Concurrent Programming
- Proseminar Software Pioneers
- By Prof. Dr. Heike Wehrheim
- Diplo. Inform. Björn Metzler
2Contents
- A brief introduction of Dijkstra and Lamport
- Problem in Concurrent Programming
- Dijkstras Solution
- Semaphores Solution
- Lamports Solution
- Conclusion
3Edsger W. Dijkstra and Leslie Lamport
- Photographs are from google photo
4Problem in Concurrent Programming
- N computers
- one critical section.
- Two requirements
- Communication between computers
- Undividable writing or reading
5Basic Goals of Dijkstras Solution
- Symmetric between N computers
- No After you After you blocking
6Dijkstras Solution
Part I Interger j Li0bifalse Li1if
k?i then Li2 begin citrue Li3
if bk then ki goto Li1
end else . .
Critical Section
1
2
3
N
i
- Code from Solution of a Problem in Concurrent
Programming Control E.W.Dijkstra
7Dijkstras Solution
Part II Li4begin cifalse for
j1 step 1 until N do if j?i and
not cj then goto Li1 end critical
section citruebitrue . . go
to Li0
Critical Section
i
1
2
3
N
Code from Solution of a Problem in Concurrent
Programming Control E.W.Dijkstra
8Problems in Dijkstras Solution
- When the i-th computer breaks down in the
critical section, the whole system will be in a
dead lock
Critical Section
????
i
Hey, we have waited too long!
1
2
3
N
What is he doing for such a long time?
Who knows. Just have to wait here.
9Semaphores 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
10Problems of Semaphores Solution
- We can no forecast or decide which process will
be removed from the waiting list. - Explicit control - deadlock
11Lamports Solution
- Begin integer j
- L1 choosingi1
- numberi1maximum(number1,...numberN)
- choosingi0
- for j1 step 1 until N do
- begin
- L2 if choosingj?0 then goto L2
- L3 if numberj?0 and (numberj,j)lt
(numberi,i) then goto L3 - end
- Critical section
- Numberi0
- Noncritical section
- Goto L1
- end
Critical Section
1
2
3
N
i
12Lamports Solution
- Begin integer j
- L1 choosingi1
- numberi1maximum(number1,...numberN)
- choosingi0
- for j1 step 1 until N do
- begin
- L2 if choosingj?0 then goto L2
- L3 if numberj?0 and (numberj,j)lt
(numberi,i) then goto L3 - end
- Critical section
- Numberi0
- Noncritical section
- Goto L1
- end
Critical Section
i
1
2
3
N
13Problems in Lamports Solution
- These computers are no longer symmetrical.
- The number attribute will be too big.
14Conclusion
- Dijkstras 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. - Lamports Solution
- Every computer got its own attribute and dont
afraid break-down in CS. - This attribute will be too huge and increase the
systems load.