Distributed System (9)

Mutual Exclusion

Ricart-Agrawala’s Algorithm

  • enter() at process Pi
    • set state to Wanted
    • multicast “Request” <Ti,Pi><T_i, P_i> to all processes
      where Ti=T_i = current Lamport timestamp at PiP_i
    • wait until all processes send back “Reply”
    • change state to Held and enter the CS
  • On receipt of a Request <Tj,Pj><T_j, P_j> at PiP_i ( iji \ne j ):
    • if (state = Held) or (state = Wanted and (Ti,i)<(Tj,j)(T_i, i) < (T_j, j) ) *// lexicographic ordering in (Tj,Pj)(T_j, P_j) *
      • add request to local queue (of waiting requests)
    • else send “Reply” to PjP_j
  • exit() at process Pi
    • change state to Released and “Reply” to all queued requests.

Maekawa’s Algorithm

put NN processes in a N\sqrt{N} by N\sqrt{N} matrix and for each PiP_i , its voting set Vi=V_i = row containing PiP_i + column containing PiP_i (each set size = 2N12\sqrt{N}-1 )


voting set

  • state = Released, voted = false
  • enter() at process Pi:
    • state = Wanted
    • Multicast Request message to all processes in ViV_i
    • Wait for Reply (vote) messages from all processes in ViV_i (including vote from self)
    • state = Held
  • exit() at process Pi:
    • state = Released
    • Multicast Release to all processes in ViV_i :
  • When PiP_i receives a Request from PjP_j :
    • if (state ==== Held OR voted ==== true)
      • queue Request
    • else
      • send Reply to PjP_j and set voted == true
  • When PiP_i receives a Release from PjP_j :
    • if (queue empty)
      • voted == false
    • else
      • dequeue head of queue as PkP_k
      • Send Reply only to PkP_k
      • voted = true

Distributed System (9)
https://yzzzf.xyz/2024/02/23/distributed-system-9/
Author
Zifan Ying
Posted on
February 23, 2024
Licensed under