Professional Documents
Culture Documents
Chapter10 TimingBasedAlgorithms
Chapter10 TimingBasedAlgorithms
q That you mention their source, after all, I would like people to use my book!
q That you note that they are adapted from (or perhaps identical to)
my slides, and note my copyright of this material.
C C M M
M M
remainder code
entry code
critical section
exit code
x 0
1 repeat
2 await(x = 0)
3 x=i
4 delay(D)
5 until x = i
6 critical section
7 x=0
// not fast
x 0
1 repeat
Can we replace
2 await(x = 0)
the order of
3 x=i these two lines?
4 delay(D)
5 until x = i
6 critical section
7 x=0
// not fast
x y 0 z 0
1 start: x=i;
2 await (y = 0)
3 y=i
4 if x ¹ i then delay(2D)
5 if y ¹ i then goto start fi
6 await (z = 0)
7 else z = 1 fi
8 critical section
9 z=0;
10 if y = i then y = 0 fi
x y 0 z 0
x y 0 z 0
1 start: x=i;
2 await (y = 0)
3 y=i
4 if x ¹ i then delay(2D)
5 if y ¹ i then goto start fi
6 await (z = 0)
7 else z = 1 fi
8 critical section Can we replace this
9 z=0; statement with: y = 0 ?
10 if y = i then y = 0 fi
x y 0 z 0
1 start: x=i;
2 await (y = 0)
3 y=i
4 if x ¹ i then delay(2D)
5 if y ¹ i then goto start fi
6 await (z = 0)
7 else z = 1 fi Can we replace the
8 critical section order of the last
9 z=0; two lines?
10 if y = i then y = 0 fi
x y 0 z 0
1 start: x=i;
2 await (y = 0) Can we replace
the order of
3 y=i
these two lines?
4 if x ¹ i then delay(2D)
5 if y ¹ i then goto start fi
6 await (z = 0)
7 else z = 1 fi
8 critical section
9 z=0;
10 if y = i then y = 0 fi
x y 0 z 0
Can we replace this statement with:
1 start: x=i; if y ¹ 0 then goto start fi ?
2 await (y = 0)
3 y=i
4 if x ¹ i then delay(2D)
5 if y ¹ i then goto start fi
6 await (z = 0)
7 else z = 1 fi
8 critical section
9 z=0;
10 if y = i then y = 0 fi
x y 0 z 0
1 start: x=i;
2 await (y = 0)
3 y=i
4 if x ¹ i then delay(2D)
5 if y ¹ i then goto start fi
6 await (z = 0)
7 else z = 1 fi
8 critical section Can we replace this statement
9 z=0; with:
10 if y = i then y = 0 fi if z ¹ 0 then goto start fi ?
1 0 1 1 0 1 0
1 1 1 1 1 1 1
requirements: Thm:
q validity There is no asynchronous
q agreement solution to the problem
using atomic registers only.
q termination
+ Wait-freedom
x ^
1 if x = ^ then x = in.i fi
2 delay(D)
3 decide (x)
x[0] 0 x[1] 0 y ^
1 x[in.i] = 1
2 if y = ^ then y = in.i fi
3 if x[1– in.i] = 1 then delay(D) fi
4 decide (y)
x[0] 0 x[1] 0 y ^
Can we replace
1 x[in.i] = 1
the order of
2 if y = ^ then y = in.i fi these two lines?
3 if x[1– in.i] = 1 then delay(D) fi
4 decide (y)
x 0 y round v out
0 ^ 1 in.i ^
1 while out = ^ do
2 x[round,v] = 1
3 if y[round] = ^ then y[round] = v fi
4 if x[round, 1-v] = 0 then out = v
5 else delay(round)
6 v = y[round]
7 round = round + 1 fi od
8 output(out).
// delay(r) ~ for j=1 to r do skip od
1 while out = ^ do
2 x[round,v] = 1
3 if y[round] = ^ then y[round] = v fi
4 if x[round, 1-v] = 0 then out = v
5 else delay(round)
6 v = y[round]
7 round = round + 1 fi od
8 output(out).
// delay(r) ~ for j=1 to r do skip od
Can we replace
the order of
1 while out = ^ do these two lines?
2 x[round,v] = 1
3 if y[round] = ^ then y[round] = v fi
4 if x[round, 1-v] = 0 then out = v
5 else delay(round)
6 v = y[round]
7 round = round + 1 fi od
8 output(out).
// delay(r) ~ for j=1 to r do skip od
Model Time
Asynchronous: impossible
Unknown: q(D log D / log log D)
Known: q(D)
• Incorrect behavior
• Satisfies safety but not liveness properties
• Correct but inefficient
Simple
Shared
Memory
x[0] 0 x[1] 0 y ^
Can it tolerate
timing failures?
1 x[in.i] = 1
No.
2 if y = ^ then y = in.i fi
3 if x[1– in.i] = 1 then delay(D) fi
4 decide (y)
x[0] 0 x[1] 0 y ^
1 x[in.i] = 1
2 if y = ^ then y = in.i fi
round 1
3 if x[1– in.i] = 1 then delay(D) else decide (y) fi
4 in.i = y
1 x[in.i] = 1
2 if y = ^ then y = in.i fi
round 2
3 if x[1– in.i] = 1 then delay(D) else decide (y) fi
4 in.i = y
x 0 y round v out
0 ^ 1 in.i ^
1 while out = ^ do
2 x[round,v] = 1
3 if y[round] = ^ then y[round] = v fi
4 if x[round, 1-v] = 0 then out = v
5 else delay(D)
6 v = y[round]
7 round = round + 1 fi od
8 output(out).
1 repeat
2 await(x = 0)
3 x=i
4 delay(D)
5 until x = i
6 entry section of A
7 critical section
8 exit section of A
9 if x = i then x = 0 fi