Download presentation
Presentation is loading. Please wait.
1
Distributed Algorithms (22903)
Atomic Snapshot Lecturer: Danny Hendler This presentation is based on the book “Distributed Computing” by Hagit attiya & Jennifer Welch.
2
Atomic snapshot objects
Each process has a SWMR register, which we call a segment A process may obtain an ‘atomic snapshot’ of all segments. Atomic Snapshot sequential specification Two operations are supported: Scan, returns a vector V, where V is an n-element vector called a view (with a value for each segment), and Updatei(d), by pi, updates pi’s segment to value d.
3
Atomic snapshot simulation
A scan collects all segments twice (double collect). If the two collects are identical, they are a snapshot What if segments change while being collected? Then we try again and again until some segment undergoes “enough” changes (we can be sure its last update started after our scan) We then use a scan embedded in that udpate
4
A wait-free simulation of atomic snapshot
Initially segment[i].ts=0, segment[i].data=vi, segment[i].view=<v0, …, vn-1> Updatei(S, d) view:=scan() Segment[i]=<segment[i].ts+1, d, view) Scani(S) for all j <> i c[j]=Segment[j] while true do for all j a[j] = Segment[j] for all j b[j] = Segment[j] if, for all j a[j]=b[j] return <b[0].data, …, b[n-1].data> ; Direct scan else if, for some j ≠ i, b[j].ts - c[j].ts ≥ 2 return b[j].view ; Indirect scan
5
Linearization order A direct scan is linearized immediately after the last read of its first collect An indirect scan is linearized at the same point as the direct scan whose view it borrowed. An update is linearized when it writes to its segment.
6
A proof that the algorithm for atomic snapshot is wait-free and linearizable
7
A space-bounded simulation of atomic snapshot
Instead of the unbounded timestamp, we use a handshaking mechanism between each pair of processes Processes pi, pj interact via two shared SRSW handshaking bits: hi, hj. ; Handshaking procedures for the ordered pair (pi, pj) procedure tryHSi() ; process pi tries to handshake with pj hi := hj procedure tryHSj() ; process pj tries to handshake with pi hj := 1-hi procedure checkHSi() process pj checks whether a handshake occurred return (hi ≠ hj) procedure checkHSj() process pj checks whether a handshake occurred return (hi = hj)
8
Handshaking properties
Handshaking property 1 If a checkHSi returns true, then there exists a tryHSj whose write occurs between the read of the previous tryHSi and the read of the checkHSi. Handshaking property 2 If a checkHSi returns false, then there is no tryHSj whose read and write occurs between the write of the previous tryHSi and the read of the checkHSi.
9
The bounded-space algorithm
Initially segment[i].data=vi, segment[i].view=<v0, …, vn-1> Local variable shook[j]=0 for all j We add a toggle bit to each data element Updatei(S, d) view:=scan() Segment[i]=<d, view, 1-Segment[i].toggle) Scani(S) for all j <> i shook[j] := 0 while true do for all j ≠ i tryHSi(i,j) for all j ≠ i a[j] = Segment[j] for all j ≠ i b[j] = Segment[j] if, for some j ≠ i, checkHSi(i,j) or (a[j].toggle ≠ a[j].toggle) if (shook[j]=2) return b[j].view ; Indirect scan else shook[j]=shook[j]+1 else if, for all j, a[j]=b[j] return <b[0].data, …, b[n-1].data> ; Direct scan
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.