Distributed System (9)
Mutual Exclusion
Ricart-Agrawala’s Algorithm
enter()
at process Pi- set state to Wanted
- multicast “Request” to all processes
where current Lamport timestamp at - wait until all processes send back “Reply”
- change state to Held and enter the CS
- On receipt of a Request at ( ):
- if (state = Held) or (state = Wanted and ) *// lexicographic ordering in *
- add request to local queue (of waiting requests)
- else send “Reply” to
- if (state = Held) or (state = Wanted and ) *// lexicographic ordering in *
exit()
at process Pi- change state to Released and “Reply” to all queued requests.
Maekawa’s Algorithm
put processes in a by matrix and for each , its voting set row containing + column containing (each set size = )
voting set
- state = Released, voted = false
enter()
at process Pi:- state = Wanted
- Multicast Request message to all processes in
- Wait for Reply (vote) messages from all processes in (including vote from self)
- state = Held
exit()
at process Pi:- state = Released
- Multicast Release to all processes in :
- When receives a Request from :
- if (state Held OR voted true)
- queue Request
- else
- send Reply to and set voted true
- if (state Held OR voted true)
- When receives a Release from :
- if (queue empty)
- voted false
- else
- dequeue head of queue as
- Send Reply only to
- voted = true
- if (queue empty)
Distributed System (9)
https://yzzzf.xyz/2024/02/23/distributed-system-9/