barrier.v 1.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
From program_logic Require Export sts.
From heap_lang Require Export derived heap wp_tactics notation.

Definition newchan := (λ: "", ref '0)%L.
Definition signal := (λ: "x", "x" <- '1)%L.
Definition wait := (rec: "wait" "x" := if: !"x" = '1 then '() else "wait" "x")%L.

(** The STS describing the main barrier protocol. *)
Module barrier_proto.
10
11
  Inductive phase := Low | High.
  Record stateT := State { state_phase : phase; state_I : gset gname }.
12
13
  Inductive token := Change (i : gname) | Send.

14
15
16
  Global Instance stateT_inhabited: Inhabited stateT.
  Proof. split. exact (State Low ). Qed.

17
18
19
  Definition change_tokens (I : gset gname) : set token :=
    mkSet (λ t, match t with Change i => i  I | Send => False end).

20
21
22
  Inductive trans : relation stateT :=
  | ChangeI p I2 I1 : trans (State p I1) (State p I2)
  | ChangePhase I : trans (State Low I) (State High I).
23

24
25
26
  Definition tok (s : stateT) : set token :=
      change_tokens (state_I s)
     match state_phase s with Low =>  | High => {[ Send ]} end.
27
28

  Definition sts := sts.STS trans tok.
29
30
31
32
33
34
35
36
37
38

  Definition i_states (i : gname) : set stateT :=
    mkSet (λ s, i  state_I s).

  Lemma i_states_closed i :
    sts.closed sts (i_states i) {[ Change i ]}.
  Proof.
    split.
    - apply non_empty_inhabited.
    
39
40
End barrier_proto.