Library zoo_parabs.ws_hub_std
From zoo Require Import
prelude.
From zoo.common Require Import
countable
gmultiset
list.
From zoo.iris.bi Require Import
big_op.
From zoo.language Require Import
notations.
From zoo.diaframe Require Import
diaframe.
From zoo_std Require Import
int
option
optional
array
random_round
domain.
From zoo_parabs Require Export
base
ws_hub_std__code.
From zoo_parabs Require Import
ws_hub_std__types
ws_deques_public
waiters.
From zoo Require Import
options.
Implicit Types b yield closed : bool.
Implicit Types num_active : Z.
Implicit Types đĄ : location.
Implicit Types v t notification notify pred : val.
Implicit Types vs : gmultiset val.
Implicit Types ws us : list val.
Implicit Types vss : list $ list val.
Implicit Types status : status.
Implicit Types empty : emptiness.
Class WsHubStdG ÎŁ `{zoo_G : !ZooG ÎŁ} :=
{ #[local] ws_hub_std_G_queues_G :: WsDequesPublicG ÎŁ
; #[local] ws_hub_std_G_waiters_G :: WaitersG ÎŁ
}.
Definition ws_hub_std_ÎŁ :=
#[ws_deques_public_ÎŁ
; waiters_ÎŁ
].
#[global] Instance subG_ws_hub_std_ÎŁ ÎŁ `{zoo_G : !ZooG ÎŁ} :
subG ws_hub_std_ÎŁ ÎŁ â
WsHubStdG ÎŁ.
#[local] Definition consistent vs vss :=
vs = â+ (list_to_set_disj <$> vss).
#[local] Lemma consistent_alloc sz :
consistent â (replicate sz []).
#[local] Lemma consistent_empty vs vss :
consistent vs vss â
vs = â â
â i us,
vss !! i = Some us â
us = [].
#[local] Lemma consistent_push {vs vss i us} v :
vss !! i = Some us â
consistent vs vss â
consistent ({[+v+]} â vs) (<[i := us ++ [v]]> vss).
#[local] Lemma consistent_remove {vs vss i us} us1 v us2 :
vss !! i = Some us â
us = us1 ++ v :: us2 â
consistent vs vss â
v â vs â§
consistent (vs â {[+v+]}) (<[i := us1 ++ us2]> vss).
#[local] Lemma consistent_pop vs vss i us v :
vss !! i = Some (us ++ [v]) â
consistent vs vss â
v â vs â§
consistent (vs â {[+v+]}) (<[i := us]> vss).
#[local] Lemma consistent_steal vs vss i v us :
vss !! i = Some (v :: us) â
consistent vs vss â
v â vs â§
consistent (vs â {[+v+]}) (<[i := us]> vss).
Opaque consistent.
Section ws_hub_std_G.
Context `{ws_hub_std_G : WsHubStdG ÎŁ}.
Implicit Types P P_notification P_pred Q Q_pred : iProp ÎŁ.
Record metadata :=
{ metadata_size : nat
; metadata_queues : val
; metadata_rounds : val
; metadata_waiters : val
}.
Implicit Types Îł : metadata.
#[local] Instance metadata_eq_dec :
EqDecision metadata.
#[local] Instance metadata_countable :
Countable metadata.
#[local] Definition inv_inner đĄ : iProp ÎŁ :=
â num_active,
đĄ.[num_active] ⊠#num_active.
#[local] Instance : CustomIpat "inv_inner" :=
" ( %num_active & HđĄ_num_active ) ".
Definition ws_hub_std_inv t Îč sz : iProp ÎŁ :=
â đĄ Îł,
ât = #đĄâ â
meta đĄ nroot Îł â
âsz = Îł.(metadata_size)â â
đĄ.[queues] âŠâĄ Îł.(metadata_queues) â
đĄ.[rounds] âŠâĄ Îł.(metadata_rounds) â
đĄ.[waiters] âŠâĄ Îł.(metadata_waiters) â
ws_deques_public_inv Îł.(metadata_queues) Îč Îł.(metadata_size) â
array_inv Îł.(metadata_rounds) Îł.(metadata_size) â
waiters_inv Îł.(metadata_waiters) sz â
inv nroot (inv_inner đĄ).
#[local] Instance : CustomIpat "inv" :=
" ( %đĄ{} & %Îł{} & {%Heq{};->} & #Hmeta{} & -> & #HđĄ{}_queues & #HđĄ{}_rounds & #HđĄ{}_waiters & #Hqueues{}_inv & #Hrounds{}_inv & #Hwaiters{}_inv & #Hinv{} ) ".
Definition ws_hub_std_model t vs : iProp ÎŁ :=
â đĄ Îł vss,
ât = #đĄâ â
meta đĄ nroot Îł â
ws_deques_public_model Îł.(metadata_queues) vss â
âconsistent vs vssâ.
#[local] Instance : CustomIpat "model" :=
" ( %đĄ_ & %Îł_ & %vss & %Heq & Hmeta_ & Hqueues_model & %Hconsistent ) ".
Definition ws_hub_std_owner t i status empty : iProp ÎŁ :=
â đĄ Îł ws round n,
ât = #đĄâ â
meta đĄ nroot Îł â
ws_deques_public_owner Îł.(metadata_queues) i status ws â
âempty = Empty â ws = []â â
array_slice Îł.(metadata_rounds) i DfracDiscarded [round] â
random_round_model' round (Îł.(metadata_size) - 1) n.
#[local] Instance : CustomIpat "owner" :=
" ( %đĄ{;_} & %Îł{;_} & %ws{} & %round{} & %n{} & %Heq{} & Hmeta{;_} & Hqueues_owner{} & %Hempty{} & #Hrounds{} & Hround{} ) ".
#[global] Instance ws_hub_std_model_timeless t vs :
Timeless (ws_hub_std_model t vs).
#[global] Instance ws_hub_std_inv_persistent t Îč sz :
Persistent (ws_hub_std_inv t Îč sz).
Lemma ws_hub_std_inv_agree t Îč sz1 sz2 :
ws_hub_std_inv t Îč sz1 -â
ws_hub_std_inv t Îč sz2 -â
âsz1 = sz2â.
Lemma ws_hub_std_owner_exclusive t i status1 empty1 status2 empty2 :
ws_hub_std_owner t i status1 empty1 -â
ws_hub_std_owner t i status2 empty2 -â
False.
Lemma ws_hub_std_inv_owner t Îč sz i status empty :
ws_hub_std_inv t Îč sz -â
ws_hub_std_owner t i status empty -â
âi < szâ.
Lemma ws_hub_std_model_empty t Îč sz vs :
ws_hub_std_inv t Îč sz -â
ws_hub_std_model t vs -â
( [â list] i â seq 0 sz,
â status,
ws_hub_std_owner t i status Empty
) -â
âvs = â â.
Lemma ws_hub_stdÙ createđspec Îč sz :
(0 †sz)%Z â
{{{
True
}}}
ws_hub_stdÙ create #sz
{{{
t
, RET t;
ws_hub_std_inv t Îč âsz â
ws_hub_std_model t â â
[â list] i â seq 0 âsz,
ws_hub_std_owner t i Nonblocked Empty
}}}.
Lemma ws_hub_stdÙ sizeđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ size t
{{{
RET #sz;
True
}}}.
#[local] Lemma ws_hub_stdÙ begin_inactiveđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ begin_inactive t
{{{
RET ();
True
}}}.
#[local] Lemma ws_hub_stdÙ end_inactiveđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ end_inactive t
{{{
RET ();
True
}}}.
#[local] Lemma ws_hub_stdÙ block_activeđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
}}}
ws_hub_stdÙ block_active t #i
{{{
RET ();
ws_hub_std_owner t i_ Blocked empty
}}}.
#[local] Lemma ws_hub_stdÙ unblock_activeđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty
}}}
ws_hub_stdÙ unblock_active t #i
{{{
RET ();
ws_hub_std_owner t i_ Nonblocked empty
}}}.
Lemma ws_hub_stdÙ blockđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
}}}
ws_hub_stdÙ block t #i
{{{
RET ();
ws_hub_std_owner t i_ Blocked empty
}}}.
Lemma ws_hub_stdÙ unblockđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty
}}}
ws_hub_stdÙ unblock t #i
{{{
RET ();
ws_hub_std_owner t i_ Nonblocked empty
}}}.
Lemma ws_hub_stdÙ closedđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ closed t
{{{
closed
, RET #closed;
True
}}}.
#[local] Lemma ws_hub_stdÙ notifyđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ notify t
{{{
RET ();
True
}}}.
#[local] Lemma ws_hub_stdÙ notify_allđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ notify_all t
{{{
RET ();
True
}}}.
Lemma ws_hub_stdÙ pushđspec t Îč sz i i_ empty v :
i = âși_ â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ push t #i v @ âÎč
<<<
ws_hub_std_model t ({[+v+]} â vs)
| RET ();
ws_hub_std_owner t i_ Nonblocked Nonempty
>>>.
Lemma ws_hub_stdÙ popđspec t Îč sz i i_ empty :
i = âși_ â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ pop t #i @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Nonblocked (if o then empty else Empty)
>>>.
#[local] Lemma ws_hub_stdÙ try_steal_onceđspec t Îč sz i i_ empty :
i = âși_ â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ try_steal_once t #i @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Blocked empty
>>>.
#[local] Lemma ws_hub_std_try_stealâđspec P Q t Îč sz i i_ empty yield max_round pred :
i = âși_ â
(0 †max_round)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty â
P â
⥠(
P -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q else P
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ try_stealâ t #i #yield #max_round pred @ âÎč
<<<
ââ o,
match o with
| Nothing
| Anything â
ws_hub_std_model t vs
| Something v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Blocked empty â
if o is Anything then Q else P
>>>.
#[local] Lemma ws_hub_stdÙ try_stealđspec P Q t Îč sz i i_ empty max_round_noyield max_round_yield pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty â
P â
⥠(
P -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q else P
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ try_steal t #i #max_round_noyield #max_round_yield pred @ âÎč
<<<
ââ o,
match o with
| Nothing
| Anything â
ws_hub_std_model t vs
| Something v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Blocked empty â
if o is Anything then Q else P
>>>.
#[local] Lemma ws_hub_stdÙ steal_auxđspec P_notification P_pred Q_pred t Îč sz i i_ empty max_round_noyield max_round_yield notification pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty â
P_notification â
( â notify,
P_notification -â
WP notify () {{ itype_unit }} -â
WP notification notify {{ res,
âres = ()%Vâ â
P_notification
}}
) â
P_pred â
⥠(
P_pred -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q_pred else P_pred
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ steal_aux t #i #max_round_noyield #max_round_yield notification pred @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ (if o then Nonblocked else Blocked) empty â
P_notification â
if o then P_pred else Q_pred
>>>.
Lemma ws_hub_stdÙ steal_untilđspec P_notification P_pred Q_pred t Îč sz i i_ empty max_round_noyield max_round_yield notification pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
( â notify,
P_notification -â
WP notify () {{ itype_unit }} -â
WP notification notify {{ res,
âres = ()%Vâ â
P_notification
}}
) â
P_pred â
⥠(
P_pred -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q_pred else P_pred
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ steal_until t #i #max_round_noyield #max_round_yield notification pred @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
if o then P_pred else Q_pred
>>>.
Lemma ws_hub_stdÙ stealđspec t Îč sz i i_ empty max_round_noyield max_round_yield :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ steal t #i #max_round_noyield #max_round_yield @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ (if o then Nonblocked else Blocked) empty
>>>.
Lemma ws_hub_stdÙ closeđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ close t
{{{
RET ();
True
}}}.
End ws_hub_std_G.
#[global] Opaque ws_hub_std_inv.
#[global] Opaque ws_hub_std_model.
#[global] Opaque ws_hub_std_owner.
Section ws_hub_std_G.
Context `{ws_hub_std_G : WsHubStdG ÎŁ}.
Implicit Types P P_notification P_pred Q Q_pred : iProp ÎŁ.
Lemma ws_hub_stdÙ pop_steal_untilđspec P_notification P_pred Q_pred t Îč sz i i_ empty max_round_noyield max_round_yield notification pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
( â notify,
P_notification -â
WP notify () {{ itype_unit }} -â
WP notification notify {{ res,
âres = ()%Vâ â
P_notification
}}
) â
P_pred â
⥠(
P_pred -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q_pred else P_pred
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ pop_steal_until t #i #max_round_noyield #max_round_yield notification pred @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| empty,
RET o;
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
if o then P_pred else Q_pred
>>>.
Lemma ws_hub_stdÙ pop_stealđspec t Îč sz i i_ empty max_round_noyield max_round_yield :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ pop_steal t #i #max_round_noyield #max_round_yield @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| empty,
RET o;
ws_hub_std_owner t i_ (if o then Nonblocked else Blocked) empty â
if o then
True
else
âempty = Emptyâ
>>>.
End ws_hub_std_G.
From zoo_parabs Require
ws_hub_std__opaque.
prelude.
From zoo.common Require Import
countable
gmultiset
list.
From zoo.iris.bi Require Import
big_op.
From zoo.language Require Import
notations.
From zoo.diaframe Require Import
diaframe.
From zoo_std Require Import
int
option
optional
array
random_round
domain.
From zoo_parabs Require Export
base
ws_hub_std__code.
From zoo_parabs Require Import
ws_hub_std__types
ws_deques_public
waiters.
From zoo Require Import
options.
Implicit Types b yield closed : bool.
Implicit Types num_active : Z.
Implicit Types đĄ : location.
Implicit Types v t notification notify pred : val.
Implicit Types vs : gmultiset val.
Implicit Types ws us : list val.
Implicit Types vss : list $ list val.
Implicit Types status : status.
Implicit Types empty : emptiness.
Class WsHubStdG ÎŁ `{zoo_G : !ZooG ÎŁ} :=
{ #[local] ws_hub_std_G_queues_G :: WsDequesPublicG ÎŁ
; #[local] ws_hub_std_G_waiters_G :: WaitersG ÎŁ
}.
Definition ws_hub_std_ÎŁ :=
#[ws_deques_public_ÎŁ
; waiters_ÎŁ
].
#[global] Instance subG_ws_hub_std_ÎŁ ÎŁ `{zoo_G : !ZooG ÎŁ} :
subG ws_hub_std_ÎŁ ÎŁ â
WsHubStdG ÎŁ.
#[local] Definition consistent vs vss :=
vs = â+ (list_to_set_disj <$> vss).
#[local] Lemma consistent_alloc sz :
consistent â (replicate sz []).
#[local] Lemma consistent_empty vs vss :
consistent vs vss â
vs = â â
â i us,
vss !! i = Some us â
us = [].
#[local] Lemma consistent_push {vs vss i us} v :
vss !! i = Some us â
consistent vs vss â
consistent ({[+v+]} â vs) (<[i := us ++ [v]]> vss).
#[local] Lemma consistent_remove {vs vss i us} us1 v us2 :
vss !! i = Some us â
us = us1 ++ v :: us2 â
consistent vs vss â
v â vs â§
consistent (vs â {[+v+]}) (<[i := us1 ++ us2]> vss).
#[local] Lemma consistent_pop vs vss i us v :
vss !! i = Some (us ++ [v]) â
consistent vs vss â
v â vs â§
consistent (vs â {[+v+]}) (<[i := us]> vss).
#[local] Lemma consistent_steal vs vss i v us :
vss !! i = Some (v :: us) â
consistent vs vss â
v â vs â§
consistent (vs â {[+v+]}) (<[i := us]> vss).
Opaque consistent.
Section ws_hub_std_G.
Context `{ws_hub_std_G : WsHubStdG ÎŁ}.
Implicit Types P P_notification P_pred Q Q_pred : iProp ÎŁ.
Record metadata :=
{ metadata_size : nat
; metadata_queues : val
; metadata_rounds : val
; metadata_waiters : val
}.
Implicit Types Îł : metadata.
#[local] Instance metadata_eq_dec :
EqDecision metadata.
#[local] Instance metadata_countable :
Countable metadata.
#[local] Definition inv_inner đĄ : iProp ÎŁ :=
â num_active,
đĄ.[num_active] ⊠#num_active.
#[local] Instance : CustomIpat "inv_inner" :=
" ( %num_active & HđĄ_num_active ) ".
Definition ws_hub_std_inv t Îč sz : iProp ÎŁ :=
â đĄ Îł,
ât = #đĄâ â
meta đĄ nroot Îł â
âsz = Îł.(metadata_size)â â
đĄ.[queues] âŠâĄ Îł.(metadata_queues) â
đĄ.[rounds] âŠâĄ Îł.(metadata_rounds) â
đĄ.[waiters] âŠâĄ Îł.(metadata_waiters) â
ws_deques_public_inv Îł.(metadata_queues) Îč Îł.(metadata_size) â
array_inv Îł.(metadata_rounds) Îł.(metadata_size) â
waiters_inv Îł.(metadata_waiters) sz â
inv nroot (inv_inner đĄ).
#[local] Instance : CustomIpat "inv" :=
" ( %đĄ{} & %Îł{} & {%Heq{};->} & #Hmeta{} & -> & #HđĄ{}_queues & #HđĄ{}_rounds & #HđĄ{}_waiters & #Hqueues{}_inv & #Hrounds{}_inv & #Hwaiters{}_inv & #Hinv{} ) ".
Definition ws_hub_std_model t vs : iProp ÎŁ :=
â đĄ Îł vss,
ât = #đĄâ â
meta đĄ nroot Îł â
ws_deques_public_model Îł.(metadata_queues) vss â
âconsistent vs vssâ.
#[local] Instance : CustomIpat "model" :=
" ( %đĄ_ & %Îł_ & %vss & %Heq & Hmeta_ & Hqueues_model & %Hconsistent ) ".
Definition ws_hub_std_owner t i status empty : iProp ÎŁ :=
â đĄ Îł ws round n,
ât = #đĄâ â
meta đĄ nroot Îł â
ws_deques_public_owner Îł.(metadata_queues) i status ws â
âempty = Empty â ws = []â â
array_slice Îł.(metadata_rounds) i DfracDiscarded [round] â
random_round_model' round (Îł.(metadata_size) - 1) n.
#[local] Instance : CustomIpat "owner" :=
" ( %đĄ{;_} & %Îł{;_} & %ws{} & %round{} & %n{} & %Heq{} & Hmeta{;_} & Hqueues_owner{} & %Hempty{} & #Hrounds{} & Hround{} ) ".
#[global] Instance ws_hub_std_model_timeless t vs :
Timeless (ws_hub_std_model t vs).
#[global] Instance ws_hub_std_inv_persistent t Îč sz :
Persistent (ws_hub_std_inv t Îč sz).
Lemma ws_hub_std_inv_agree t Îč sz1 sz2 :
ws_hub_std_inv t Îč sz1 -â
ws_hub_std_inv t Îč sz2 -â
âsz1 = sz2â.
Lemma ws_hub_std_owner_exclusive t i status1 empty1 status2 empty2 :
ws_hub_std_owner t i status1 empty1 -â
ws_hub_std_owner t i status2 empty2 -â
False.
Lemma ws_hub_std_inv_owner t Îč sz i status empty :
ws_hub_std_inv t Îč sz -â
ws_hub_std_owner t i status empty -â
âi < szâ.
Lemma ws_hub_std_model_empty t Îč sz vs :
ws_hub_std_inv t Îč sz -â
ws_hub_std_model t vs -â
( [â list] i â seq 0 sz,
â status,
ws_hub_std_owner t i status Empty
) -â
âvs = â â.
Lemma ws_hub_stdÙ createđspec Îč sz :
(0 †sz)%Z â
{{{
True
}}}
ws_hub_stdÙ create #sz
{{{
t
, RET t;
ws_hub_std_inv t Îč âsz â
ws_hub_std_model t â â
[â list] i â seq 0 âsz,
ws_hub_std_owner t i Nonblocked Empty
}}}.
Lemma ws_hub_stdÙ sizeđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ size t
{{{
RET #sz;
True
}}}.
#[local] Lemma ws_hub_stdÙ begin_inactiveđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ begin_inactive t
{{{
RET ();
True
}}}.
#[local] Lemma ws_hub_stdÙ end_inactiveđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ end_inactive t
{{{
RET ();
True
}}}.
#[local] Lemma ws_hub_stdÙ block_activeđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
}}}
ws_hub_stdÙ block_active t #i
{{{
RET ();
ws_hub_std_owner t i_ Blocked empty
}}}.
#[local] Lemma ws_hub_stdÙ unblock_activeđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty
}}}
ws_hub_stdÙ unblock_active t #i
{{{
RET ();
ws_hub_std_owner t i_ Nonblocked empty
}}}.
Lemma ws_hub_stdÙ blockđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
}}}
ws_hub_stdÙ block t #i
{{{
RET ();
ws_hub_std_owner t i_ Blocked empty
}}}.
Lemma ws_hub_stdÙ unblockđspec t Îč sz i i_ empty :
i = âși_ â
{{{
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty
}}}
ws_hub_stdÙ unblock t #i
{{{
RET ();
ws_hub_std_owner t i_ Nonblocked empty
}}}.
Lemma ws_hub_stdÙ closedđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ closed t
{{{
closed
, RET #closed;
True
}}}.
#[local] Lemma ws_hub_stdÙ notifyđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ notify t
{{{
RET ();
True
}}}.
#[local] Lemma ws_hub_stdÙ notify_allđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ notify_all t
{{{
RET ();
True
}}}.
Lemma ws_hub_stdÙ pushđspec t Îč sz i i_ empty v :
i = âși_ â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ push t #i v @ âÎč
<<<
ws_hub_std_model t ({[+v+]} â vs)
| RET ();
ws_hub_std_owner t i_ Nonblocked Nonempty
>>>.
Lemma ws_hub_stdÙ popđspec t Îč sz i i_ empty :
i = âși_ â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ pop t #i @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Nonblocked (if o then empty else Empty)
>>>.
#[local] Lemma ws_hub_stdÙ try_steal_onceđspec t Îč sz i i_ empty :
i = âși_ â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ try_steal_once t #i @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Blocked empty
>>>.
#[local] Lemma ws_hub_std_try_stealâđspec P Q t Îč sz i i_ empty yield max_round pred :
i = âși_ â
(0 †max_round)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty â
P â
⥠(
P -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q else P
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ try_stealâ t #i #yield #max_round pred @ âÎč
<<<
ââ o,
match o with
| Nothing
| Anything â
ws_hub_std_model t vs
| Something v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Blocked empty â
if o is Anything then Q else P
>>>.
#[local] Lemma ws_hub_stdÙ try_stealđspec P Q t Îč sz i i_ empty max_round_noyield max_round_yield pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty â
P â
⥠(
P -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q else P
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ try_steal t #i #max_round_noyield #max_round_yield pred @ âÎč
<<<
ââ o,
match o with
| Nothing
| Anything â
ws_hub_std_model t vs
| Something v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Blocked empty â
if o is Anything then Q else P
>>>.
#[local] Lemma ws_hub_stdÙ steal_auxđspec P_notification P_pred Q_pred t Îč sz i i_ empty max_round_noyield max_round_yield notification pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Blocked empty â
P_notification â
( â notify,
P_notification -â
WP notify () {{ itype_unit }} -â
WP notification notify {{ res,
âres = ()%Vâ â
P_notification
}}
) â
P_pred â
⥠(
P_pred -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q_pred else P_pred
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ steal_aux t #i #max_round_noyield #max_round_yield notification pred @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ (if o then Nonblocked else Blocked) empty â
P_notification â
if o then P_pred else Q_pred
>>>.
Lemma ws_hub_stdÙ steal_untilđspec P_notification P_pred Q_pred t Îč sz i i_ empty max_round_noyield max_round_yield notification pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
( â notify,
P_notification -â
WP notify () {{ itype_unit }} -â
WP notification notify {{ res,
âres = ()%Vâ â
P_notification
}}
) â
P_pred â
⥠(
P_pred -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q_pred else P_pred
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ steal_until t #i #max_round_noyield #max_round_yield notification pred @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
if o then P_pred else Q_pred
>>>.
Lemma ws_hub_stdÙ stealđspec t Îč sz i i_ empty max_round_noyield max_round_yield :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ steal t #i #max_round_noyield #max_round_yield @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| RET o;
ws_hub_std_owner t i_ (if o then Nonblocked else Blocked) empty
>>>.
Lemma ws_hub_stdÙ closeđspec t Îč sz :
{{{
ws_hub_std_inv t Îč sz
}}}
ws_hub_stdÙ close t
{{{
RET ();
True
}}}.
End ws_hub_std_G.
#[global] Opaque ws_hub_std_inv.
#[global] Opaque ws_hub_std_model.
#[global] Opaque ws_hub_std_owner.
Section ws_hub_std_G.
Context `{ws_hub_std_G : WsHubStdG ÎŁ}.
Implicit Types P P_notification P_pred Q Q_pred : iProp ÎŁ.
Lemma ws_hub_stdÙ pop_steal_untilđspec P_notification P_pred Q_pred t Îč sz i i_ empty max_round_noyield max_round_yield notification pred :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
( â notify,
P_notification -â
WP notify () {{ itype_unit }} -â
WP notification notify {{ res,
âres = ()%Vâ â
P_notification
}}
) â
P_pred â
⥠(
P_pred -â
WP pred () {{ res,
â b,
âres = #bâ â
if b then Q_pred else P_pred
}}
)
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ pop_steal_until t #i #max_round_noyield #max_round_yield notification pred @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| empty,
RET o;
ws_hub_std_owner t i_ Nonblocked empty â
P_notification â
if o then P_pred else Q_pred
>>>.
Lemma ws_hub_stdÙ pop_stealđspec t Îč sz i i_ empty max_round_noyield max_round_yield :
i = âși_ â
(0 †max_round_noyield)%Z â
(0 †max_round_yield)%Z â
<<<
ws_hub_std_inv t Îč sz â
ws_hub_std_owner t i_ Nonblocked empty
| ââ vs,
ws_hub_std_model t vs
>>>
ws_hub_stdÙ pop_steal t #i #max_round_noyield #max_round_yield @ âÎč
<<<
ââ o,
match o with
| None â
ws_hub_std_model t vs
| Some v â
â vs',
âvs = {[+v+]} â vs'â â
ws_hub_std_model t vs'
end
| empty,
RET o;
ws_hub_std_owner t i_ (if o then Nonblocked else Blocked) empty â
if o then
True
else
âempty = Emptyâ
>>>.
End ws_hub_std_G.
From zoo_parabs Require
ws_hub_std__opaque.