200 likes | 352 Views
Mutual Exclusion. Critical Section Problem. acquire(c) CriticalSection c release(c) Critical Section correctness Mutual Exclusion: safety (ME1) Deadlock-Freedom: progress (ME2a) Starvation-Freedom: fairness (ME2b) [Happens-Before Ordering (ME3)]. Algorithms. Centralized algorithm
E N D
Critical Section Problem acquire(c) CriticalSection c release(c) • Critical Section correctness • Mutual Exclusion: safety (ME1) • Deadlock-Freedom: progress (ME2a) • Starvation-Freedom: fairness (ME2b) • [Happens-Before Ordering (ME3)]
Algorithms • Centralized algorithm • Distributed algorithm • Token Ring algorithm
Centralized Algorithm • Leader process grants access • Requests queued in order received • Three types of messages: • Request(P,c) – Process P requests CS c • Acquire(P,c) – Leader grants P access to c • Release(P,c) – P is done with CS c
Example – Centralized Alg (1/3) 1 0 2 Acquire(1,c) Request(1,c) 3 CS process c 1
Example – Centralized Alg (2/3) 1 0 2 Request(2,c) 3 Queue for c Request(2,c) CS process c 1
Example – Centralized Alg (3/3) 1 0 2 Release(1,c) Acquire(2,c) 3 Queue for c Request(2,c) CS process c 1 CS process c 2
Token Ring Algorithm • Organize processes in (logical) ring • Initialize – pass first process token • Token continually passed around the ring • Acquire CS when receiving token • If CS not needed, pass token along • When releasing CS, pass token to successor
Distributed Algorithm • No leader process • Need total order on messages • Broadcast all messages • Lamport’s timestamps • Two message types: • request(P,c,ts) – P requests CS c at time ts • acquire(P,Q,c) – Q permits P to enter c • P acquires c – all proc permit P to enter c
Example – Distributed Alg (1/7) Wanted 1 Request(1,c,8) Request(1,c,8) Acquire(1,0,c) 0 2 Released Request(1,c,8) Released Acquire(1,3,c) 3 Released
Example – Distributed Alg (2/7) Wanted Acquire from 0,3 1 Request(1,c,8) Acquire(1,0,c) 0 2 Released Released Acquire(1,3,c) 3 Released
Example – Distributed Alg (3/7) Acquire from 0,3 1 Request(2,c,6) Request(1,c,8) Wanted 0 2 Released Request(2,c,6) Released Request(2,c,6) 3 Released
Example – Distributed Alg (4/7) Acquire from 0,3 1 Request(2,c,6) Wanted Request(1,c,8) Acquire from 0,3 0 2 Released Acquire(2,0,c) Wanted Acquire(2,3,c) 3 Released
Example – Distributed Alg (5/7) Acquire from 0,3 1 Request(2,c,6) Wanted Request(1,c,8) 0 2 Released Acquire from 0,3 Wanted Queue Request(1,c,8) Receives request 3 Released
Example – Distributed Alg (6/7) Acquire from 0,3 1 Request(2,c,6) Wanted Acquire(2,1,c) 0 2 Released Acquire from 0,3 Receive request Wanted Queue Request(1,c,8) 3 Released
Example – Distributed Alg (7/7) Acquire from 0,3 1 Enters CS Wanted Acquire(1,2,c) 0 2 Released Wanted Queue Request(1,c,8) Held Released 3 Released