grub-fork/csp/sync.csp

37 lines
997 B
Text
Raw Normal View History

S = 3
STATES = {0..S-1}
2015-08-15 12:14:27 +00:00
channel input, render, up, down, save, saved:STATES
2015-08-13 18:58:03 +00:00
apply(state, patch) = (state + patch) % S
diff(state1, state2) = (state2 - state1) % S
2015-08-13 19:25:18 +00:00
CLIENT(i, state, shadow) =
2015-08-15 12:14:27 +00:00
input?new_state
-> up!diff(shadow, new_state)
-> CLIENT(i, new_state, shadow)
[] down?patch
-> if patch != 0
then render!apply(state, patch) -> CLIENT(i, apply(state, patch), apply(shadow, patch))
else CLIENT(i, state, state)
2015-08-13 19:41:30 +00:00
2015-08-15 12:14:27 +00:00
SERVER(i, shadow) =
up?patch
-> save!patch
-> saved?new_state
-> down!diff(apply(shadow, patch), new_state)
-> SERVER(i, apply(shadow, patch))
[] saved?new_state
-> if (new_state == shadow)
then SERVER(i, shadow)
else down!diff(shadow, new_state) -> SERVER(i, new_state)
2015-08-13 19:41:30 +00:00
2015-08-15 12:14:27 +00:00
DB(state) = save?patch -> saved!apply(state, patch) -> DB(apply(state, patch))
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]]