Ranvier.Heap.Concurrency
Heap concurrency, thread affinity, and inbox contracts
This module lifts the concurrency, Serialised reentrant holder, inbox handover, and PendingDispatch
contracts of Pure/Concurrency.v to HeapLang separation logic:
guarded_enter_spec:Guardedthread-affinity gate (AssertOnGraphThread/Enter).serialised_acquire_specandserialised_release_spec:Serialisedreentrant holder lock (CASonholder, context check, andReleasewith non-empty inbox drain re-post).post_queued_spec: cross-thread inbox enqueue (PostQueued) and drain wake post.pending_dispatch_claim_specandpending_dispatch_close_spec: atomicCASclaim (TryClaim) and cancellation/abandon (TryClose) onPendingDispatch.read_memo_fast_spec,signal_set_fast_split_spec,default_comparer_null_sentinel_spec, andfast_write_token_spec:.NEThot/cold fast-path specifications forMemo.Value,Signal.Value,ComparerSentinel, andGraph.fastWriteToken/OwnerThreadToken.
7
From stdpp Require Import prelude gmap.
From Stdlib Require Import ZArith.
From Ranvier.Base Require Import Prelude Syntax.
From Ranvier.Pure Require Import State Engine Scheduler Concurrency.
From iris.heap_lang Require Import proofmode notation.
From Ranvier.Heap Require Import ObserverSet SourceList Ghost Marking Run Scheduler.
Open Scope nat_scope.HeapLang code for concurrency, holder lock, inbox, and PendingDispatch
Layout of a 6-cell concurrency control block cs:
cs +ₗ 0: affinity (0=Guarded,1=Unchecked,2=Serialised)cs +ₗ 1:ownerThreadcs +ₗ 2:contextcs +ₗ 3:holder(0when free,me > 0when held)cs +ₗ 4:inbox(HeapLang list of work item ids)cs +ₗ 5:pumpPosted(boolean)
Definition affinity_val (aff : thread_affinity) : val :=
Definition affinity_val (aff : thread_affinity) : val :=
match aff with
| AffGuarded => #0
| AffUnchecked => #1
| AffSerialised => #2
end.Definition guarded_enter_code : val :=
Definition guarded_enter_code : val :=
λ: "cs" "me",
let: "owner" := !("cs" +ₗ #1) in
if: "me" = "owner" then SOME #false
else NONE.Definition serialised_enter_code : val :=
Definition serialised_enter_code : val :=
λ: "cs" "me" "ctx",
let: "h" := !("cs" +ₗ #3) in
if: "h" = "me" then SOME #false
else
let: "c" := !("cs" +ₗ #2) in
if: "ctx" = "c" then
if: CAS ("cs" +ₗ #3) #0 "me" then SOME #true
else NONE
else NONE.Definition serialised_release_code : val :=
Definition serialised_release_code : val :=
λ: "cs",
("cs" +ₗ #3) <- #0;;
let: "inb" := !("cs" +ₗ #4) in
match: "inb" with
NONE => #()
| SOME <> => ("cs" +ₗ #5) <- #true
end.Definition post_queued_code : val :=
Definition post_queued_code : val :=
λ: "cs" "w",
let: "inb" := !("cs" +ₗ #4) in
("cs" +ₗ #4) <- vlist_snoc_code "inb" "w";;
if: !"cs" = #2 then ("cs" +ₗ #5) <- #true
else (if: CAS ("cs" +ₗ #5) #false #true then #() else #()).References
Uses
- vlist_snoc_code
- false
- true
- heap_lang.val
- CAS
Definition pd_try_claim_code : val :=
Definition pd_try_claim_code : val :=
λ: "pd",
CAS "pd" #0 #1.Definition pd_try_close_code : val :=
Definition pd_try_close_code : val :=
λ: "pd",
CAS "pd" #0 #2.Definition aff_enter_code : val :=
Definition aff_enter_code : val :=
λ: "cs" "me" "ctx",
let: "aff" := !"cs" in
if: "aff" = #0 then guarded_enter_code "cs" "me"
else if: "aff" = #1 then SOME #false
else serialised_enter_code "cs" "me" "ctx".References
Uses
- guarded_enter_code
- serialised_enter_code
- false
- heap_lang.val
- SOME
Definition read_memo_fast_code : val :=
Definition read_memo_fast_code : val :=
λ: "g" "n",
match: graph_get_node_code "g" "n" with
NONE => read_code "g" "n" #true
| SOME "d" =>
let: "k" := Fst (Fst (Fst (Fst "d"))) in
if: "k" = #1 then
let: "fr" := Fst (Fst (Snd (Fst "d"))) in
let: "st" := Snd (Snd (Fst (Fst "d"))) in
if: (BinOp OrOp "fr" (BinOp AndOp "st" #3)) = #0 then
track_code "g" "n";;
InjL (Snd (Fst (Fst (Fst "d"))))
else
read_code "g" "n" #true
else
read_code "g" "n" #true
end.References
Uses
- graph_get_node_code
- track_code
- read_code
- true
- heap_lang.AndOp
- heap_lang.BinOp
- heap_lang.Fst
- heap_lang.InjL
3 more
- heap_lang.OrOp
- heap_lang.Snd
- heap_lang.val
Used by
Definition signal_set_after_acquire_code : val :=
Definition signal_set_after_acquire_code : val :=
λ: "cs" "g" "n" "v",
match: graph_get_node_code "g" "n" with
NONE => serialised_release_code "cs";; NONE
| SOME "d" =>
let: "cur" := Snd (Fst (Fst (Fst "d"))) in
if: "cur" = "v" then
serialised_release_code "cs";; SOME #()
else
write_signal_code "g" "n" "v";;
serialised_release_code "cs";;
SOME #()
end.References
Uses
- graph_get_node_code
- write_signal_code
- serialised_release_code
- heap_lang.Fst
- heap_lang.Snd
- heap_lang.val
- NONE
- SOME
Definition signal_set_fast_split_code : val :=
Definition signal_set_fast_split_code : val :=
λ: "cs" "me" "ctx" "g" "n" "v",
match: aff_enter_code "cs" "me" "ctx" with
NONE => NONE
| SOME "must_rel" =>
if: "must_rel" then
signal_set_after_acquire_code "cs" "g" "n" "v"
else
match: graph_get_node_code "g" "n" with
NONE => NONE
| SOME "d" =>
let: "cur" := Snd (Fst (Fst (Fst "d"))) in
if: "cur" = "v" then SOME #()
else
write_signal_code "g" "n" "v";;
SOME #()
end
end.References
Uses
- graph_get_node_code
- write_signal_code
- aff_enter_code
- signal_set_after_acquire_code
- heap_lang.Fst
- heap_lang.Snd
- heap_lang.val
- NONE
1 more
- SOME
Definition null_comparer_code : val :=
Definition null_comparer_code : val :=
λ: <> <>, InjR (#0, #0).References
Uses
- heap_lang.InjR
- heap_lang.val
Definition encode_comparer_code : val :=
Definition encode_comparer_code : val :=
λ: "is_val_type" "is_val_def" "is_ref_id" "opt_cmp",
match: "opt_cmp" with
NONE => SOME null_comparer_code
| SOME "f" =>
if: "is_val_type" then
(if: "is_val_def" then NONE else SOME "f")
else
(if: "is_ref_id" then NONE else SOME "f")
end.Definition eval_comparer_sentinel_code : val :=
Definition eval_comparer_sentinel_code : val :=
λ: "is_val_type" "enc" "a" "b",
if: "is_val_type" then
match: "enc" with
NONE => InjL ("a" = "b")
| SOME "cmp" => "cmp" "a" "b"
end
else
match: "enc" with
NONE => InjL ("a" = "b")
| SOME "cmp" => "cmp" "a" "b"
end.Definition check_fast_write_token_code : val :=
Definition check_fast_write_token_code : val :=
λ: "tok_loc" "caller_tok",
let: "tok" := !"tok_loc" in
if: #0 ≤ "tok" then
(if: "tok" = #0 then #true else "tok" = "caller_tok")
else #false.Definition signal_set_token_fast_code : val :=
Definition signal_set_token_fast_code : val :=
λ: "tok_loc" "caller_tok" "cs" "me" "ctx" "g" "n" "v",
if: check_fast_write_token_code "tok_loc" "caller_tok" then
match: graph_get_node_code "g" "n" with
NONE => NONE
| SOME "d" =>
let: "cur" := Snd (Fst (Fst (Fst "d"))) in
if: "cur" = "v" then SOME #()
else
write_signal_code "g" "n" "v";;
SOME #()
end
else
signal_set_fast_split_code "cs" "me" "ctx" "g" "n" "v".References
Uses
- graph_get_node_code
- write_signal_code
- signal_set_fast_split_code
- check_fast_write_token_code
- heap_lang.Fst
- heap_lang.Snd
- heap_lang.val
- NONE
1 more
- SOME
Used by
Section heap_concurrency.
References
Uses
- graphG
- Σ:3
- heapGS
Definition is_concurrency_state (cs_loc : loc) (cs : concurrency_state) : iProp Σ :=
Definition is_concurrency_state (cs_loc : loc) (cs : concurrency_state) : iProp Σ :=
cs_loc ↦ affinity_val (cs_affinity cs) ∗
(cs_loc +ₗ 1) ↦ #(Z.of_nat (cs_owner_thread cs)) ∗
(cs_loc +ₗ 2) ↦ #(Z.of_nat (cs_context cs)) ∗
(cs_loc +ₗ 3) ↦ #(Z.of_nat (cs_holder cs)) ∗
(cs_loc +ₗ 4) ↦ list_val (cs_inbox cs) ∗
(cs_loc +ₗ 5) ↦ #(cs_pump_posted cs).References
Uses
5 more
- affinity_val
- heap_concurrency.Σ
- Z.of_nat
- iProp_solution.iProp
- loc
Definition enter_res_val (res : option (concurrency_state * bool)) : val :=
Definition enter_res_val (res : option (concurrency_state * bool)) : val :=
match res with
| None => NONEV
| Some (_, b) => SOMEV #b
end.References
Uses
- concurrency_state
- None
- Some
- bool
- option
- heap_lang.val
- NONEV
- SOMEV
guarded_enter_code checks me = cs_owner_thread without mutating is_concurrency_state, returning SOME #false on the owner thread and NONE off-thread.
Arguments
cs_affinity cs = AffGuarded.Theorem guarded_enter_spec (cs_loc : loc) (me ctx : nat) (cs : concurrency_state) :
Theorem guarded_enter_spec (cs_loc : loc) (me ctx : nat) (cs : concurrency_state) :
cs_affinity cs = AffGuarded ->
{{{ is_concurrency_state cs_loc cs }}}
guarded_enter_code #cs_loc #(Z.of_nat me)
{{{ RET enter_res_val (graph_enter me ctx cs); is_concurrency_state cs_loc cs }}}.
Arguments
cs_affinity cs = AffGuarded.Qed
Proof.
intros Haff.
iIntros (Φ) "(H0 & H1 & H2 & H3 & H4 & H5) HΦ".
rewrite /guarded_enter_code /graph_enter Haff /=.
wp_lam. wp_pures. wp_load. wp_pures.
destruct (decide (me = cs_owner_thread cs)) as [->|Hne].
- rewrite bool_decide_eq_true_2 //. wp_pures. iModIntro.
iApply "HΦ". rewrite /is_concurrency_state Haff /=. iFrame.
- rewrite bool_decide_eq_false_2; [|intros Heq; injection Heq as Heq; apply Hne; lia].
wp_pures. iModIntro.
iApply "HΦ". rewrite /is_concurrency_state Haff /=. iFrame.
Qed.References
Uses
- AffGuarded
- concurrency_state
- cs_affinity
- cs_owner_thread
- graph_enter
- guarded_enter_code
- is_concurrency_state
- enter_res_val
6 more
- nat
- Z.of_nat
- loc
- decide
- bool_decide_eq_false_2
- bool_decide_eq_true_2
Used by
serialised_enter_code implements reentrant Serialised acquisition via CAS on holder (cs_loc +ₗ 3) and context verification (cs_loc +ₗ 2).
Covers all three outcomes of graph_enter under AffSerialised:
- Reentrant entry (
cs_holder cs = me): returnsSOME #falseand preservescs. - Outermost entry (
cs_holder cs = 0andctx = cs_context cs):CAStransitionsholderfrom0tomeand returnsSOME #true. - Contended or wrong-context entry: returns
NONEand leavescsuntouched.
Arguments
me > 0).SynchronizationContext id.cs_affinity cs = AffSerialised.Theorem serialised_acquire_spec (cs_loc : loc) (me ctx : nat) (cs : concurrency_state) :
Theorem serialised_acquire_spec (cs_loc : loc) (me ctx : nat) (cs : concurrency_state) :
cs_affinity cs = AffSerialised ->
{{{ is_concurrency_state cs_loc cs }}}
serialised_enter_code #cs_loc #(Z.of_nat me) #(Z.of_nat ctx)
{{{ RET enter_res_val (graph_enter me ctx cs);
is_concurrency_state cs_loc
(match graph_enter me ctx cs with Some (cs', _) => cs' | None => cs end) }}}.
Arguments
me > 0).SynchronizationContext id.cs_affinity cs = AffSerialised.Qed
Proof.
intros Haff.
iIntros (Φ) "(H0 & H1 & H2 & H3 & H4 & H5) HΦ".
rewrite /serialised_enter_code /graph_enter Haff /=.
wp_lam. wp_pures. wp_load. wp_pures.
destruct (decide (cs_holder cs = me)) as [Hhold|Hne].
- rewrite Hhold bool_decide_eq_true_2 //. wp_pures. iModIntro.
iApply "HΦ". rewrite /is_concurrency_state Haff Hhold /=. iFrame.
- rewrite bool_decide_eq_false_2; [|intros Heq; injection Heq as Heq; apply Hne; lia].
wp_pures. wp_load. wp_pures.
destruct (decide (ctx = cs_context cs /\ cs_holder cs = 0)) as [[Hctx Hfree]|Hbad].
+ rewrite Hctx bool_decide_eq_true_2 //. wp_pures.
rewrite Hfree.
wp_cmpxchg_suc; [done|]. wp_pures. iModIntro.
iApply "HΦ". rewrite /is_concurrency_state /=. iFrame.
+ destruct (decide (ctx = cs_context cs)) as [Hctx|Hctx_ne].
* assert (Hnh : cs_holder cs ≠ 0) by (intros H0; apply Hbad; split; done).
rewrite Hctx bool_decide_eq_true_2 //. wp_pures.
wp_cmpxchg_fail; [intros Heq; injection Heq as Heq; apply Hnh; lia|].
wp_pures. iModIntro. iApply "HΦ". rewrite /is_concurrency_state Haff /=. iFrame.
* rewrite bool_decide_eq_false_2; [|intros Heq; injection Heq as Heq; apply Hctx_ne; lia].
wp_pures. iModIntro. iApply "HΦ". rewrite /is_concurrency_state Haff /=. iFrame.
Qed.References
Uses
- AffSerialised
- concurrency_state
- cs_affinity
- cs_context
- cs_holder
- graph_enter
- serialised_enter_code
- is_concurrency_state
9 more
- enter_res_val
- None
- Some
- nat
- Z.of_nat
- loc
- decide
- bool_decide_eq_false_2
- bool_decide_eq_true_2
Used by
serialised_release_code clears holder to 0 and sets pumpPosted = true whenever cs_inbox is non-empty (graph_release).
Arguments
Release.Theorem serialised_release_spec (cs_loc : loc) (cs : concurrency_state) :
Theorem serialised_release_spec (cs_loc : loc) (cs : concurrency_state) :
{{{ is_concurrency_state cs_loc cs }}}
serialised_release_code #cs_loc
{{{ RET #(); is_concurrency_state cs_loc (graph_release cs) }}}.
Arguments
Release.Qed
Proof.
iIntros (Φ) "(H0 & H1 & H2 & H3 & H4 & H5) HΦ".
rewrite /serialised_release_code /graph_release.
wp_lam. wp_pures. wp_store. wp_load.
destruct (cs_inbox cs) as [|w ws] eqn:Einb; simpl; wp_pures.
- iModIntro. iApply "HΦ". rewrite /is_concurrency_state /=. iFrame.
- wp_store. iModIntro. iApply "HΦ". rewrite /is_concurrency_state /=. iFrame.
Qed.post_queued_code appends work item w to the FIFO inbox and leaves pumpPosted = true: by a store under Serialised, and otherwise by a CAS from false that posts a drain only when none is pending (post_queued).
Arguments
PostQueued.Theorem post_queued_spec (cs_loc : loc) (w : nat) (cs : concurrency_state) :
Theorem post_queued_spec (cs_loc : loc) (w : nat) (cs : concurrency_state) :
{{{ is_concurrency_state cs_loc cs }}}
post_queued_code #cs_loc #(Z.of_nat w)
{{{ RET #();
⌜drain_guaranteed (post_queued w cs)⌝ ∗
is_concurrency_state cs_loc (post_queued w cs) }}}.
Arguments
PostQueued.Qed
Proof.
iIntros (Φ) "(H0 & H1 & H2 & H3 & H4 & H5) HΦ".
rewrite /post_queued_code /post_queued.
wp_lam. wp_pures. wp_load. wp_pures.
rewrite (list_val_eq (cs_inbox cs)).
wp_apply (vlist_snoc_spec (fun k : nat => #(Z.of_nat k)) (cs_inbox cs) w); [done|].
iIntros "_". wp_store. wp_load.
(* `Serialised` posts on every call; the other affinities post when `CAS` moves `pumpPosted` from false to true. *)
destruct (cs_affinity cs); simpl; wp_pures.
- destruct (cs_pump_posted cs); [wp_cmpxchg_fail|wp_cmpxchg_suc]; wp_pures; iModIntro; iApply "HΦ";
(iSplit;
[iPureIntro; intros _; left; reflexivity
|rewrite /is_concurrency_state /= (list_val_eq (cs_inbox cs ++ [w])); iFrame]).
- destruct (cs_pump_posted cs); [wp_cmpxchg_fail|wp_cmpxchg_suc]; wp_pures; iModIntro; iApply "HΦ";
(iSplit;
[iPureIntro; intros _; left; reflexivity
|rewrite /is_concurrency_state /= (list_val_eq (cs_inbox cs ++ [w])); iFrame]).
- wp_store. iModIntro. iApply "HΦ". iSplit.
+ iPureIntro. intros _. left. reflexivity.
+ rewrite /is_concurrency_state /= (list_val_eq (cs_inbox cs ++ [w])). iFrame.
Qed.pd_try_claim_code atomically transitions a PendingDispatch cell from 0 (Waiting) to 1 (Claimed) via CAS (pd_try_claim).
Arguments
PendingDispatch state location.0 = waiting, 1 = claimed, 2 = closed).Theorem pending_dispatch_claim_spec (pd : loc) (st : pd_state) :
Theorem pending_dispatch_claim_spec (pd : loc) (st : pd_state) :
{{{ pd ↦ #(Z.of_nat st) }}}
pd_try_claim_code #pd
{{{ RET #(snd (pd_try_claim st)); pd ↦ #(Z.of_nat (fst (pd_try_claim st))) }}}.
Arguments
PendingDispatch state location.0 = waiting, 1 = claimed, 2 = closed).Qed
Proof.
iIntros (Φ) "Hpd HΦ".
rewrite /pd_try_claim_code /pd_try_claim.
wp_lam.
destruct (decide (st = 0)) as [->|Hne].
- wp_cmpxchg_suc; [done|]. wp_pures. iModIntro. by iApply "HΦ".
- wp_cmpxchg_fail; [intros Heq; injection Heq as Heq; apply Hne; lia|].
wp_pures. iModIntro. by iApply "HΦ".
Qed.pd_try_close_code atomically transitions a PendingDispatch cell from 0 (Waiting) to 2 (Closed) via CAS (pd_try_close).
Arguments
PendingDispatch state location.0 = waiting, 1 = claimed, 2 = closed).Theorem pending_dispatch_close_spec (pd : loc) (st : pd_state) :
Theorem pending_dispatch_close_spec (pd : loc) (st : pd_state) :
{{{ pd ↦ #(Z.of_nat st) }}}
pd_try_close_code #pd
{{{ RET #(snd (pd_try_close st)); pd ↦ #(Z.of_nat (fst (pd_try_close st))) }}}.
Arguments
PendingDispatch state location.0 = waiting, 1 = claimed, 2 = closed).Qed
Proof.
iIntros (Φ) "Hpd HΦ".
rewrite /pd_try_close_code /pd_try_close.
wp_lam.
destruct (decide (st = 0)) as [->|Hne].
- wp_cmpxchg_suc; [done|]. wp_pures. iModIntro. by iApply "HΦ".
- wp_cmpxchg_fail; [intros Heq; injection Heq as Heq; apply Hne; lia|].
wp_pures. iModIntro. by iApply "HΦ".
Qed.Hot/cold fast-path specifications for Memo.Value and Signal.Value
Lemma aff_enter_spec (cs_loc : loc) (me ctx : nat) (cs : concurrency_state) :
Lemma aff_enter_spec (cs_loc : loc) (me ctx : nat) (cs : concurrency_state) :
{{{ is_concurrency_state cs_loc cs }}}
aff_enter_code #cs_loc #(Z.of_nat me) #(Z.of_nat ctx)
{{{ RET enter_res_val (graph_enter me ctx cs);
is_concurrency_state cs_loc
(match graph_enter me ctx cs with Some (cs', _) => cs' | None => cs end) }}}.
Qed
Proof.
iIntros (Φ) "(H0 & H1 & H2 & H3 & H4 & H5) HΦ".
rewrite /aff_enter_code. wp_lam. wp_pures. wp_load. wp_pures.
destruct (cs_affinity cs) eqn:Haff; simpl; wp_pures.
- wp_apply (guarded_enter_spec cs_loc me ctx cs Haff with "[H0 H1 H2 H3 H4 H5]").
+ rewrite /is_concurrency_state Haff /=. iFrame.
+ iIntros "Hcs".
destruct (guarded_enter_iff_owner me ctx cs Haff) as [[_ Hsome] [Hne _]].
destruct (decide (me = cs_owner_thread cs)) as [Heq|Hneq].
* assert (Hge : graph_enter me ctx cs = Some (cs, false)) by (by apply Hsome).
rewrite Hge. by iApply "HΦ".
* assert (Hge : graph_enter me ctx cs = None) by (by apply Hne).
rewrite Hge. by iApply "HΦ".
- rewrite /graph_enter Haff /=. iModIntro.
iApply "HΦ". rewrite /is_concurrency_state Haff /=. iFrame.
- wp_apply (serialised_acquire_spec cs_loc me ctx cs Haff with "[H0 H1 H2 H3 H4 H5]").
+ rewrite /is_concurrency_state Haff /=. iFrame.
+ done.
Qed.References
Uses
- concurrency_state
- cs_affinity
- cs_owner_thread
- graph_enter
- guarded_enter_iff_owner
- aff_enter_code
- is_concurrency_state
- enter_res_val
9 more
- guarded_enter_spec
- serialised_acquire_spec
- None
- Some
- false
- nat
- Z.of_nat
- loc
- decide
Used by
read_memo_fast_code inspects freshness and status &&& 3 inline to track and return clean cached memo values directly while matching read_code across all states.
Arguments
Theorem read_memo_fast_spec γ g (n : node_id) (s : State.state) (fuel : nat) (s' : State.state) (r : outcome) :
Theorem read_memo_fast_spec γ g (n : node_id) (s : State.state) (fuel : nat) (s' : State.state) (r : outcome) :
read fuel n true s = Some (s', r) ->
{{{ is_graph γ g s }}}
read_memo_fast_code g #(Z.of_nat n)
{{{ RET outcome_val r; is_graph γ g s' }}}.
Arguments
Qed
Proof.
intros Hread. iIntros (Φ) "Hg HΦ".
rewrite /read_memo_fast_code. wp_lam. wp_pures.
wp_apply (graph_get_node_spec with "Hg"). iIntros "Hg".
destruct (g_nodes s !! n) as [d|] eqn:Hnode; simpl.
- rewrite /node_val /node_val_a /node_val_b /node_val_c /node_val_d.
wp_pures.
destruct (n_kind d) eqn:Hk; simpl; wp_pures.
+ wp_apply (read_spec _ _ n true s fuel s' r Hread with "Hg"). iExact "HΦ".
+ destruct (n_freshness d) eqn:Hfr, (n_status d) eqn:Hst; simpl; wp_pures.
1: {
destruct fuel as [|fuel']; [done|].
destruct fuel' as [|f]; [done|].
pose proof (proj2 (memo_read_fast_split_eq f n s)) as Hsplit.
rewrite Hsplit /read_memo_fast in Hread.
unfold m_bind, m_return, get_node in Hread. simpl in Hread.
rewrite Hnode Hk Hfr Hst in Hread.
assert (Hc : is_clean_and_ready_bits Clean StNone false = true) by reflexivity.
rewrite Hc in Hread.
destruct (track n s) as [[s1 []]|] eqn:Htr; [|discriminate Hread].
injection Hread as -> <-.
assert (Hndom : n ∈ dom (g_nodes s)) by (by apply elem_of_dom_2 in Hnode).
wp_apply (track_spec _ _ n s s' Hndom Htr with "Hg"). iIntros "Hg".
wp_pures. by iApply "HΦ".
}
all: wp_apply (read_spec _ _ n true s fuel s' r Hread with "Hg"); iExact "HΦ".
+ wp_apply (read_spec _ _ n true s fuel s' r Hread with "Hg"). iExact "HΦ".
- wp_pures.
wp_apply (read_spec _ _ n true s fuel s' r Hread with "Hg"). iExact "HΦ".
Qed.References
Uses
Used by
signal_set_fast_split_code enters affinity first (aff_enter_code), short-circuits unjournaled equal writes without write_signal_code or serialised_release_code when must_rel = false, and releases acquired Serialised locks cleanly.
Arguments
SynchronizationContext id.write_signal (S f).write_signal (S f) n v s.n.Theorem signal_set_fast_split_spec
Theorem signal_set_fast_split_spec
γ g (cs_loc : loc) (me ctx f : nat) (n : node_id) (v : Z)
(cs : concurrency_state) (s s_w : State.state) (d : node) :
g_nodes s !! n = Some d ->
n_kind d = KSignal ->
write_signal (S f) n v s = Some (s_w, tt) ->
{{{ is_concurrency_state cs_loc cs ∗ is_graph γ g s }}}
signal_set_fast_split_code #cs_loc #(Z.of_nat me) #(Z.of_nat ctx) g #(Z.of_nat n) #v
{{{ RET match signal_set_fast_split me ctx (S f) n v cs None s with
| Some _ => SOMEV #()
| None => NONEV
end;
match signal_set_fast_split me ctx (S f) n v cs None s with
| Some (cs', _, s') => is_concurrency_state cs_loc cs' ∗ is_graph γ g s'
| None => is_concurrency_state cs_loc cs ∗ is_graph γ g s
end }}}.
Arguments
SynchronizationContext id.write_signal (S f).write_signal (S f) n v s.n.Qed
Proof.
intros Hnode Hk Hws.
iIntros (Φ) "(Hcs & Hg) HΦ".
rewrite /signal_set_fast_split_code. wp_lam. wp_pures.
wp_apply (aff_enter_spec cs_loc me ctx cs with "Hcs"). iIntros "Hcs".
destruct (graph_enter me ctx cs) as [[cs1 []]|] eqn:Hge; simpl; wp_pures.
- rewrite /signal_set_after_acquire_code. wp_lam. wp_pures.
wp_apply (graph_get_node_spec with "Hg"). iIntros "Hg".
rewrite Hnode /node_val /node_val_a /node_val_b /node_val_c /node_val_d /=.
wp_pures.
destruct (decide (n_value d = v)) as [Heq|Hne].
+ rewrite Heq bool_decide_eq_true_2 //. wp_pures.
wp_apply (serialised_release_spec cs_loc cs1 with "Hcs"). iIntros "Hcs".
wp_pures. iModIntro.
rewrite /signal_set_fast_split /signal_set_after_acquire Hge Hnode Hk decide_True //.
iApply "HΦ". iFrame.
+ rewrite bool_decide_eq_false_2; [|intros Hc; injection Hc as Hc; apply Hne; lia].
wp_pures.
wp_apply (write_signal_spec γ g n v s (S f) s_w Hws with "Hg"). iIntros "Hg".
wp_pures.
wp_apply (serialised_release_spec cs_loc cs1 with "Hcs"). iIntros "Hcs".
wp_pures. iModIntro.
rewrite /signal_set_fast_split /signal_set_after_acquire Hge Hnode Hk decide_False // Hws /=.
iApply "HΦ". iFrame.
- wp_apply (graph_get_node_spec with "Hg"). iIntros "Hg".
rewrite Hnode /node_val /node_val_a /node_val_b /node_val_c /node_val_d /=.
wp_pures.
destruct (decide (n_value d = v)) as [Heq|Hne].
+ rewrite Heq bool_decide_eq_true_2 //. wp_pures. iModIntro.
rewrite /signal_set_fast_split Hge Hnode Hk decide_True //.
iApply "HΦ". iFrame.
+ rewrite bool_decide_eq_false_2; [|intros Hc; injection Hc as Hc; apply Hne; lia].
wp_pures.
wp_apply (write_signal_spec γ g n v s (S f) s_w Hws with "Hg"). iIntros "Hg".
wp_pures. iModIntro.
rewrite /signal_set_fast_split Hge Hnode Hk decide_False // Hws /=.
iApply "HΦ". iFrame.
- rewrite /signal_set_fast_split Hge.
iModIntro. iApply "HΦ". iFrame.
Qed.References
Uses
32 more
- concurrency_state
- graph_enter
- signal_set_after_acquire
- signal_set_fast_split
- node_val_a
- node_val_b
- node_val_c
- node_val_d
- node_val
- is_graph
- graph_get_node_spec
- write_signal_spec
- signal_set_after_acquire_code
- signal_set_fast_split_code
- is_concurrency_state
- serialised_release_spec
- aff_enter_spec
- None
- S
- Some
- nat
- tt
- Z
- Z.of_nat
- loc
- NONEV
- SOMEV
- decide
- bool_decide_eq_false_2
- bool_decide_eq_true_2
- decide_False
- decide_True
Definition cmp_outcome_val (out : cmp_outcome) : val :=
Definition cmp_outcome_val (out : cmp_outcome) : val :=
match out with
| CmpBool b => InjLV #b
| CmpNullRef => InjRV (#0, #0)
| CmpThrow err => InjRV (#1, #err)
end.References
Uses
- cmp_outcome
- CmpBool
- CmpNullRef
- CmpThrow
- heap_lang.InjLV
- heap_lang.InjRV
- heap_lang.val
Definition eq_prim_code : val :=
Definition eq_prim_code : val :=
λ: "x" "y", InjL ("x" = "y").References
Uses
- heap_lang.InjL
- heap_lang.val
Definition nullable_comparer_args (c : nullable_comparer) (fv : val) : val * val * val :=
Definition nullable_comparer_args (c : nullable_comparer) (fv : val) : val * val * val :=
match c with
| CmpNullInput => (#false, #false, NONEV)
| CmpValDefault => (#true, #false, SOMEV eq_prim_code)
| CmpRefIdentity => (#false, #true, SOMEV eq_prim_code)
| CmpCustomInput _ => (#false, #false, SOMEV fv)
end.References
Uses
3 more
- heap_lang.val
- NONEV
- SOMEV
encode_comparer_code followed by eval_comparer_sentinel_code encodes value-type EqualityComparer<'T>.Default and reference-type ReferenceComparer<'T> as NONE (null) evaluated via primitive =, raises CmpNullRef via null_comparer_code when the input comparer was NONE, and invokes other comparers unchanged.
Arguments
true when typeof<'T>.IsValueType, false otherwise.c = CmpCustomInput f.Theorem default_comparer_null_sentinel_spec
Theorem default_comparer_null_sentinel_spec
(is_val_type : bool) (c : nullable_comparer) (fv : val) (a b : Z) :
(forall f, c = CmpCustomInput f ->
{{{ True }}} fv #a #b {{{ RET cmp_outcome_val (f a b); True }}}) ->
let '(is_val_def, is_ref_id, opt_cmp) := nullable_comparer_args c fv in
{{{ True }}}
let: "enc" := encode_comparer_code #is_val_type is_val_def is_ref_id opt_cmp in
eval_comparer_sentinel_code #is_val_type "enc" #a #b
{{{ RET cmp_outcome_val (eval_nullable_comparer Z.eqb Z.eqb c a b); True }}}.
Arguments
true when typeof<'T>.IsValueType, false otherwise.c = CmpCustomInput f.Qed
Proof.
intros Hcustom.
destruct is_val_type, c as [| | |f]; simpl; iIntros (Φ) "_ HΦ".
- rewrite /encode_comparer_code /eval_comparer_sentinel_code /null_comparer_code.
wp_pures. iModIntro. by iApply "HΦ".
- rewrite /encode_comparer_code /eval_comparer_sentinel_code.
wp_pures. iModIntro.
replace (bool_decide (#a = #b)) with (Z.eqb a b).
+ by iApply "HΦ".
+ symmetry. destruct (Z.eqb_spec a b) as [->|Hne].
* by rewrite bool_decide_eq_true_2.
* rewrite bool_decide_eq_false_2 //; intros [= H]; exact (Hne H).
- rewrite /encode_comparer_code /eval_comparer_sentinel_code /eq_prim_code.
wp_pures. iModIntro.
replace (bool_decide (#a = #b)) with (Z.eqb a b).
+ by iApply "HΦ".
+ symmetry. destruct (Z.eqb_spec a b) as [->|Hne].
* by rewrite bool_decide_eq_true_2.
* rewrite bool_decide_eq_false_2 //; intros [= H]; exact (Hne H).
- rewrite /encode_comparer_code /eval_comparer_sentinel_code.
wp_pures.
wp_apply (Hcustom f eq_refl with "[//]").
iIntros "_". by iApply "HΦ".
- rewrite /encode_comparer_code /eval_comparer_sentinel_code /null_comparer_code.
wp_pures. iModIntro. by iApply "HΦ".
- rewrite /encode_comparer_code /eval_comparer_sentinel_code /eq_prim_code.
wp_pures. iModIntro.
replace (bool_decide (#a = #b)) with (Z.eqb a b).
+ by iApply "HΦ".
+ symmetry. destruct (Z.eqb_spec a b) as [->|Hne].
* by rewrite bool_decide_eq_true_2.
* rewrite bool_decide_eq_false_2 //; intros [= H]; exact (Hne H).
- rewrite /encode_comparer_code /eval_comparer_sentinel_code.
wp_pures. iModIntro.
replace (bool_decide (#a = #b)) with (Z.eqb a b).
+ by iApply "HΦ".
+ symmetry. destruct (Z.eqb_spec a b) as [->|Hne].
* by rewrite bool_decide_eq_true_2.
* rewrite bool_decide_eq_false_2 //; intros [= H]; exact (Hne H).
- rewrite /encode_comparer_code /eval_comparer_sentinel_code.
wp_pures.
wp_apply (Hcustom f eq_refl with "[//]").
iIntros "_". by iApply "HΦ".
Qed.References
Uses
- nullable_comparer
- CmpCustomInput
- eval_nullable_comparer
- null_comparer_code
- encode_comparer_code
- eval_comparer_sentinel_code
- cmp_outcome_val
- eq_prim_code
10 more
- nullable_comparer_args
- bool
- eq_refl
- Z
- Z.eqb
- Z.eqb_spec
- heap_lang.val
- bool_decide
- bool_decide_eq_false_2
- bool_decide_eq_true_2
Used by
Lemma check_fast_write_token_spec (tok_loc : loc) (tok caller_tok : Z) :
Lemma check_fast_write_token_spec (tok_loc : loc) (tok caller_tok : Z) :
{{{ tok_loc ↦ #tok }}}
check_fast_write_token_code #tok_loc #caller_tok
{{{ RET #(check_fast_write_token tok caller_tok); tok_loc ↦ #tok }}}.
Qed
Proof.
iIntros (Φ) "Htok HΦ".
rewrite /check_fast_write_token_code /check_fast_write_token.
wp_lam. wp_pures. wp_load. wp_pures.
destruct (decide (0 <= tok)%Z) as [Hnn|Hneg].
- rewrite !(bool_decide_eq_true_2 (0 <= tok)%Z) //=.
wp_pures.
destruct (decide (tok = 0%Z)) as [->|Hnt0].
+ rewrite (bool_decide_eq_true_2 (0%Z = 0%Z)) //=.
wp_pures. iModIntro. by iApply "HΦ".
+ rewrite (bool_decide_eq_false_2 (tok = 0%Z)) //=.
rewrite (bool_decide_eq_false_2 (#tok = #0)); [|intros [= H]; exact (Hnt0 H)].
wp_pures.
destruct (decide (tok = caller_tok)) as [->|Hntc].
* rewrite (bool_decide_eq_true_2 (caller_tok = caller_tok)) //.
rewrite (bool_decide_eq_true_2 (#caller_tok = #caller_tok)) //.
iModIntro. by iApply "HΦ".
* rewrite (bool_decide_eq_false_2 (tok = caller_tok)) //.
rewrite (bool_decide_eq_false_2 (#tok = #caller_tok)); [|intros [= H]; exact (Hntc H)].
iModIntro. by iApply "HΦ".
- rewrite !(bool_decide_eq_false_2 (0 <= tok)%Z) //=.
wp_pures. iModIntro. by iApply "HΦ".
Qed.References
Uses
- check_fast_write_token
- check_fast_write_token_code
- Z
- loc
- decide
- bool_decide_eq_false_2
- bool_decide_eq_true_2
Used by
signal_set_token_fast_code loads fastWriteToken (tok_loc) and compares against 0 or caller_tok to bypass aff_enter_code on unjournaled Unchecked and owner-thread Guarded writes while refining signal_set_entered identically across all affinities and threads.
Arguments
fastWriteToken cell location.>= 1) assigned to cs_owner_thread cs.OwnerThreadToken.Current on the calling thread (>= 0).SynchronizationContext id.write_signal (S f).write_signal (S f) n v s.n.Theorem fast_write_token_spec
Theorem fast_write_token_spec
γ g (tok_loc cs_loc : loc) (owner_tok caller_tok : Z)
(me ctx f : nat) (n : node_id) (v : Z)
(cs : concurrency_state) (s s_w : State.state) (d : node) :
(1 <= owner_tok)%Z ->
(0 <= caller_tok)%Z ->
(caller_tok = owner_tok <-> me = cs_owner_thread cs) ->
g_nodes s !! n = Some d ->
n_kind d = KSignal ->
write_signal (S f) n v s = Some (s_w, tt) ->
let tok := compute_fast_write_token (cs_affinity cs) false owner_tok in
{{{ tok_loc ↦ #tok ∗ is_concurrency_state cs_loc cs ∗ is_graph γ g s }}}
signal_set_token_fast_code #tok_loc #caller_tok #cs_loc #(Z.of_nat me) #(Z.of_nat ctx) g #(Z.of_nat n) #v
{{{ RET match signal_set_entered me ctx (S f) n v cs None s with
| Some _ => SOMEV #()
| None => NONEV
end;
tok_loc ↦ #tok ∗
match signal_set_entered me ctx (S f) n v cs None s with
| Some (cs', _, s') => is_concurrency_state cs_loc cs' ∗ is_graph γ g s'
| None => is_concurrency_state cs_loc cs ∗ is_graph γ g s
end }}}.
Arguments
fastWriteToken cell location.>= 1) assigned to cs_owner_thread cs.OwnerThreadToken.Current on the calling thread (>= 0).SynchronizationContext id.write_signal (S f).write_signal (S f) n v s.n.Qed
Proof.
intros Hown Hcaller Htok_eq Hnode Hk Hws. cbv zeta.
set (tok := compute_fast_write_token (cs_affinity cs) false owner_tok).
destruct (fast_write_token_iff owner_tok caller_tok me ctx f n v cs None s Hown Hcaller Htok_eq)
as (_ & _ & Href).
assert (Hbody :
signal_set_entered me ctx (S f) n v cs None s =
if check_fast_write_token tok caller_tok then
if decide (n_value d = v) then Some (cs, None, s) else Some (cs, None, s_w)
else
signal_set_fast_split me ctx (S f) n v cs None s).
{ rewrite <- Href. unfold signal_set_token_fast.
rewrite Hnode. cbv beta iota zeta.
rewrite Hk Hws. reflexivity. }
rewrite Hbody.
iIntros (Φ) "(Htok & Hcs & Hg) HΦ".
rewrite /signal_set_token_fast_code. wp_lam. wp_pures.
wp_apply (check_fast_write_token_spec tok_loc tok caller_tok with "Htok").
iIntros "Htok".
destruct (check_fast_write_token tok caller_tok) eqn:Hchk; wp_pures.
- wp_apply (graph_get_node_spec with "Hg"). iIntros "Hg".
rewrite Hnode /node_val /node_val_a /node_val_b /node_val_c /node_val_d /=.
wp_pures.
destruct (decide (n_value d = v)) as [Heq|Hne].
+ rewrite Heq bool_decide_eq_true_2 //. wp_pures. iModIntro.
iApply "HΦ". iFrame.
+ rewrite bool_decide_eq_false_2; [|intros [= Hc]; exact (Hne Hc)].
wp_pures.
wp_apply (write_signal_spec γ g n v s (S f) s_w Hws with "Hg"). iIntros "Hg".
wp_pures. iModIntro.
iApply "HΦ". iFrame.
- wp_apply (signal_set_fast_split_spec γ g cs_loc me ctx f n v cs s s_w d Hnode Hk Hws with "[$Hcs $Hg]").
iIntros "Hpost".
iApply "HΦ". iFrame.
Qed.References
Uses
35 more
- concurrency_state
- cs_affinity
- cs_owner_thread
- signal_set_entered
- signal_set_fast_split
- compute_fast_write_token
- check_fast_write_token
- signal_set_token_fast
- fast_write_token_iff
- node_val_a
- node_val_b
- node_val_c
- node_val_d
- node_val
- is_graph
- graph_get_node_spec
- write_signal_spec
- signal_set_token_fast_code
- is_concurrency_state
- signal_set_fast_split_spec
- check_fast_write_token_spec
- None
- S
- Some
- false
- nat
- tt
- Z
- Z.of_nat
- loc
- NONEV
- SOMEV
- decide
- bool_decide_eq_false_2
- bool_decide_eq_true_2
Used by
Coalescing SignalPort HeapLang specifications
Heap layout of a 4-cell SignalPort block port_loc:
port_loc +ₗ 0:disposed(boolean)port_loc +ₗ 1:inInbox(boolean)port_loc +ₗ 2:hasPending(boolean)port_loc +ₗ 3:pendingVal(integer value'T)
Definition signal_port_post_off_code : val :=
Definition signal_port_post_off_code : val :=
λ: "port" "cs" "drain_id" "v",
if: !"port" then #()
else
("port" +ₗ #3) <- "v";;
("port" +ₗ #2) <- #true;;
if: !("port" +ₗ #1) then #()
else
("port" +ₗ #1) <- #true;;
post_queued_code "cs" "drain_id".Definition signal_port_post_inline_code : val :=
Definition signal_port_post_inline_code : val :=
λ: "port" "g" "n" "v",
if: !"port" then #()
else
(if: !("port" +ₗ #2) then
("port" +ₗ #2) <- #false;;
("port" +ₗ #3) <- #0
else #());;
write_signal_code "g" "n" "v";;
#().Definition signal_port_drain_code : val :=
Definition signal_port_drain_code : val :=
λ: "port" "g" "n",
if: !("port" +ₗ #1) then
let: "take" := !("port" +ₗ #2) in
let: "v" := !("port" +ₗ #3) in
("port" +ₗ #1) <- #false;;
("port" +ₗ #2) <- #false;;
("port" +ₗ #3) <- #0;;
if: !"port" then #()
else if: "take" then
write_signal_code "g" "n" "v";;
#()
else #()
else #().Definition is_signal_port (port_loc : loc) (st : signal_port_state) : iProp Σ :=
Definition is_signal_port (port_loc : loc) (st : signal_port_state) : iProp Σ :=
port_loc ↦ #(sp_disposed st) ∗
(port_loc +ₗ 1) ↦ #(sp_in_inbox st) ∗
(port_loc +ₗ 2) ↦ #(sp_has_pending st) ∗
(port_loc +ₗ 3) ↦ #(sp_pending_val st).References
Uses
- signal_port_state
- sp_disposed
- sp_in_inbox
- sp_has_pending
- sp_pending_val
- heap_concurrency.Σ
- iProp_solution.iProp
- loc
signal_port_post_off_code coalesces off-thread posts in port_loc, enqueuing drain_id via post_queued_code iff sp_in_inbox = false, and drops posts silently when sp_disposed = true.
Arguments
SignalPort heap block.drain callback.signal_port_state before Post.concurrency_state.Theorem signal_port_post_off_spec
Theorem signal_port_post_off_spec
(port_loc cs_loc : loc) (drain_id : nat) (v : Z)
(st : signal_port_state) (cs : concurrency_state) :
sp_pending_attr st = None ->
{{{ is_signal_port port_loc st ∗ is_concurrency_state cs_loc cs }}}
signal_port_post_off_code #port_loc #cs_loc #(Z.of_nat drain_id) #v
{{{ RET #();
is_signal_port port_loc (sp_post_off v None st) ∗
is_concurrency_state cs_loc
(if sp_disposed st || sp_in_inbox st then cs else post_queued drain_id cs) }}}.
Arguments
SignalPort heap block.drain callback.signal_port_state before Post.concurrency_state.Qed
Proof.
intros Hattr.
iIntros (Φ) "((Hd & Hin & Hp & Hv) & Hcs) HΦ".
rewrite /signal_port_post_off_code /sp_post_off.
wp_lam. wp_pures. wp_load.
destruct (sp_disposed st) eqn:Edisp; wp_pures.
- iModIntro. iApply "HΦ". rewrite /is_signal_port Edisp /=. iFrame.
- wp_store. wp_store. wp_load.
destruct (sp_in_inbox st) eqn:Ein; simpl; wp_pures.
+ iModIntro. iApply "HΦ". rewrite /is_signal_port /=. iFrame.
+ wp_store.
wp_apply (post_queued_spec cs_loc drain_id cs with "Hcs").
iIntros "[_ Hcs]".
iApply "HΦ". rewrite /is_signal_port /=. iFrame.
Qed.References
Uses
- concurrency_state
- post_queued
- signal_port_state
- sp_disposed
- sp_in_inbox
- sp_pending_attr
- sp_post_off
- is_concurrency_state
8 more
- post_queued_spec
- signal_port_post_off_code
- is_signal_port
- None
- nat
- Z
- Z.of_nat
- loc
Used by
signal_port_post_inline_code clears any pending off-thread value (hasPending := false, pendingVal := 0) before applying write_signal_code inline on the owning thread, and drops silently when sp_disposed = true.
Arguments
SignalPort heap block.write_signal (S f).signal_port_state before inline Post.Post.write_signal (S f) n v s.Theorem signal_port_post_inline_spec
Theorem signal_port_post_inline_spec
γ g (port_loc : loc) (f : nat) (n : node_id) (v : Z)
(st : signal_port_state) (s s_w : State.state) :
write_signal (S f) n v s = Some (s_w, tt) ->
{{{ is_signal_port port_loc st ∗ is_graph γ g s }}}
signal_port_post_inline_code #port_loc g #(Z.of_nat n) #v
{{{ RET #();
is_signal_port port_loc (sp_post_inline v st) ∗
is_graph γ g (if sp_disposed st then s else s_w) }}}.
Arguments
SignalPort heap block.write_signal (S f).signal_port_state before inline Post.Post.write_signal (S f) n v s.Qed
Proof.
intros Hws.
iIntros (Φ) "((Hd & Hin & Hp & Hv) & Hg) HΦ".
rewrite /signal_port_post_inline_code /sp_post_inline.
wp_lam. wp_pures. wp_load.
destruct (sp_disposed st) eqn:Edisp; wp_pures.
- iModIntro. iApply "HΦ". rewrite /is_signal_port Edisp /=. iFrame.
- wp_load.
destruct (sp_has_pending st) eqn:Epend; wp_pures.
+ wp_store. wp_store.
wp_apply (write_signal_spec γ g n v s (S f) s_w Hws with "Hg").
iIntros "Hg". wp_pures. iModIntro.
iApply "HΦ". rewrite /is_signal_port /=. iFrame.
+ wp_apply (write_signal_spec γ g n v s (S f) s_w Hws with "Hg").
iIntros "Hg". wp_pures. iModIntro.
iApply "HΦ". rewrite /is_signal_port /=. iFrame.
Qed.References
Uses
10 more
- write_signal_spec
- signal_port_post_inline_code
- is_signal_port
- S
- Some
- nat
- tt
- Z
- Z.of_nat
- loc
Used by
signal_port_drain_code resets inInbox, hasPending, and pendingVal to idle, applies write_signal_code with sp_pending_val iff sp_in_inbox = true, sp_disposed = false, and sp_has_pending = true, and skips superseded or disposed drains cleanly.
Arguments
SignalPort heap block.write_signal (S f).signal_port_state before Drain.Drain.write_signal (S f) n (sp_pending_val st) s.Theorem signal_port_drain_spec
Theorem signal_port_drain_spec
γ g (port_loc : loc) (f : nat) (n : node_id)
(st : signal_port_state) (s s_w : State.state) :
write_signal (S f) n (sp_pending_val st) s = Some (s_w, tt) ->
{{{ is_signal_port port_loc st ∗ is_graph γ g s }}}
signal_port_drain_code #port_loc g #(Z.of_nat n)
{{{ RET #();
is_signal_port port_loc (sp_drain st) ∗
is_graph γ g
(if sp_in_inbox st && negb (sp_disposed st) && sp_has_pending st then s_w else s) }}}.
Arguments
SignalPort heap block.write_signal (S f).signal_port_state before Drain.Drain.write_signal (S f) n (sp_pending_val st) s.Qed
Proof.
intros Hws.
iIntros (Φ) "((Hd & Hin & Hp & Hv) & Hg) HΦ".
rewrite /signal_port_drain_code /sp_drain.
wp_lam. wp_pures. wp_load.
destruct (sp_in_inbox st) eqn:Ein; simpl; wp_pures.
- wp_load. wp_pures. wp_load. wp_pures.
wp_store. wp_store. wp_store. wp_load.
destruct (sp_disposed st) eqn:Edisp; simpl; wp_pures.
+ iModIntro. iApply "HΦ". rewrite /is_signal_port /=. iFrame.
+ destruct (sp_has_pending st) eqn:Epend; simpl; wp_pures.
* wp_apply (write_signal_spec γ g n (sp_pending_val st) s (S f) s_w Hws with "Hg").
iIntros "Hg". wp_pures. iModIntro.
iApply "HΦ". rewrite /is_signal_port /=. iFrame.
* iModIntro. iApply "HΦ". rewrite /is_signal_port /=. iFrame.
- iModIntro. iApply "HΦ". rewrite /is_signal_port Ein /=. iFrame.
Qed.References
Uses
12 more
- sp_drain
- is_graph
- write_signal_spec
- signal_port_drain_code
- is_signal_port
- S
- Some
- nat
- negb
- tt
- Z.of_nat
- loc
Used by
End heap_concurrency.