2015-08-15 13:51:25 +00:00
|
|
|
N = 2
|
2015-08-15 11:58:59 +00:00
|
|
|
S = 3
|
2015-08-15 13:51:25 +00:00
|
|
|
CLIENTS = {0..N-1}
|
2015-08-15 11:58:59 +00:00
|
|
|
STATES = {0..S-1}
|
2015-08-15 13:51:25 +00:00
|
|
|
channel input, render, up, down, save, saved:CLIENTS.STATES
|
2015-08-13 18:58:03 +00:00
|
|
|
|
2015-08-15 11:58:59 +00:00
|
|
|
apply(state, patch) = (state + patch) % S
|
|
|
|
diff(state1, state2) = (state2 - state1) % S
|
2015-08-15 13:38:20 +00:00
|
|
|
empty(patch) = patch == 0
|
2015-08-13 19:25:18 +00:00
|
|
|
|
2015-08-15 11:58:59 +00:00
|
|
|
CLIENT(i, state, shadow) =
|
2015-08-15 13:51:25 +00:00
|
|
|
input.i?new_state
|
|
|
|
-> up!i!diff(shadow, new_state)
|
2015-08-15 12:14:27 +00:00
|
|
|
-> CLIENT(i, new_state, shadow)
|
2015-08-15 13:51:25 +00:00
|
|
|
[] down.i?patch
|
2015-08-15 13:38:20 +00:00
|
|
|
-> if empty(patch)
|
|
|
|
then CLIENT(i, state, state)
|
|
|
|
else
|
|
|
|
if diff(apply(shadow, patch), apply(state, patch)) != 0
|
2015-08-15 13:51:25 +00:00
|
|
|
then
|
|
|
|
render!i!apply(state, patch)
|
|
|
|
-> up!i!diff(apply(shadow, patch), apply(state, patch))
|
|
|
|
-> CLIENT(i, apply(state, patch), apply(shadow, patch))
|
|
|
|
else
|
|
|
|
render!i!apply(state, patch)
|
|
|
|
-> CLIENT(i, apply(state, patch), apply(shadow, patch))
|
2015-08-13 19:41:30 +00:00
|
|
|
|
2015-08-15 12:14:27 +00:00
|
|
|
SERVER(i, shadow) =
|
2015-08-15 13:51:25 +00:00
|
|
|
up.i?patch
|
|
|
|
-> save!i!patch
|
|
|
|
-> saved.i?new_state
|
|
|
|
-> down!i!diff(apply(shadow, patch), new_state)
|
2015-08-15 12:14:27 +00:00
|
|
|
-> SERVER(i, apply(shadow, patch))
|
2015-08-15 13:51:25 +00:00
|
|
|
[] saved?j?new_state
|
2015-08-15 12:14:27 +00:00
|
|
|
-> if (new_state == shadow)
|
|
|
|
then SERVER(i, shadow)
|
2015-08-15 13:51:25 +00:00
|
|
|
else down!i!diff(shadow, new_state) -> SERVER(i, new_state)
|
2015-08-13 19:41:30 +00:00
|
|
|
|
2015-08-15 13:51:25 +00:00
|
|
|
DB(state) = save?i?patch -> saved!i!apply(state, patch) -> DB(apply(state, patch))
|
2015-08-15 12:14:27 +00:00
|
|
|
|
|
|
|
state = 0
|
|
|
|
SYSTEM = CLIENT(0, state, state)
|
|
|
|
||| CLIENT(1, state, state)
|
|
|
|
||| SERVER(0, state)
|
|
|
|
||| SERVER(1, state)
|
|
|
|
||| DB(state)
|
2015-08-13 18:58:03 +00:00
|
|
|
|
|
|
|
assert SYSTEM :[deadlock free [F]]
|