Section SyncCallsDiagrams.
Context (hb: nat).
(*Instantiate definitions in Concur with the current hybridbound*)
Notation concur_match:= (concur_match hb).
Notation match_thread:= (match_thread hb).
Notation match_thread_source:= (match_thread_source hb).
Notation match_thread_target:= (match_thread_target hb).
Notation memcompat2:= (memcompat2 hb).
Notation memcompat1:= (memcompat1 hb).
Notation contains12:= (contains12 hb).
Notation mtch_target:= (mtch_target hb).
Notation mtch_compiled:= (mtch_compiled hb).
Notation mtch_source:= (mtch_source hb).
Notation thread_perms st i cnt:= (fst (@getThreadR _ _ st i cnt)).
Notation lock_perms st i cnt:= (snd (@getThreadR  _ _ st i cnt)).
(* Thread states *)
(* angel,lock permissions and new thread permissions *)
(*Hangel_bound: sub_map_virtue angel (getMaxPerm m1)*)

Lemma release_step_diagram_self Sem:
let CoreSem:= sem_coresem Sem in
forall (SelfSim: (self_simulation (@semC Sem) CoreSem))
(st1 : mach_state hb) (st2 : mach_state (S hb))
(m1 m1' m2 : mem) (mu : meminj) tid i b b' ofs delt
(Hinj_b : mu b = Some (b', delt))
cnt1 cnt2 (* Threads are contained *)
(CMatch: concur_match i mu st1 m1 st2 m2)
(th_state1: @semC Sem) th_state2 sum_state1 sum_state2
(HState1: coerce_state_type _ sum_state1 th_state1
(CSem, Clight.state) (AsmSem,Asm.state) (Sem,@semC Sem))
(HState2: coerce_state_type _ sum_state2 th_state2
(CSem, Clight.state) (AsmSem,Asm.state) (Sem,@semC Sem))
(Hget_th_state1: @getThreadC _ _ tid st1 cnt1 = Kblocked sum_state1)
(Hget_th_state2: @getThreadC _ _ tid st2 cnt2 = Kblocked sum_state2)
(angel: virtue) empty_perms
(Hempty_map: empty_doublemap empty_perms)
(HisLock: lockRes st1 (b, Integers.Ptrofs.unsigned ofs) = Some empty_perms)
(Hangel_bound: sub_map_virtue angel (getMaxPerm m1))
(Hthread_mem1: access_map_equiv (thread_perms tid st1 cnt1) (getCurPerm m1))
(Hthread_mem2: access_map_equiv (thread_perms tid st2 cnt2) (getCurPerm m2)),
let Hcmpt2:= memcompat2 CMatch in
let newThreadPerm1:= (computeMap_pair (getThreadR cnt1) (virtueThread angel)) in
forall (Hjoin_angel: permMapJoin_pair newThreadPerm1 (virtueLP angel) (getThreadR cnt1))
(Hlock_update_mem_strict_load: lock_update_mem_strict_load b (unsigned ofs)
(snd (getThreadR cnt1))
m1 m1' vzero vone)
(Amatch : match_self (code_inject _ _ SelfSim) mu th_state1 m1 th_state2 m2)
(Hat_external: semantics.at_external CoreSem th_state1 m1 =
Some (UNLOCK, (Vptr b ofs :: nil)%list)),
let event1 := build_release_event (b, unsigned ofs) (fst (virtueThread angel)) m1' in
exists event2 (m2' : mem),
match_self (code_inject _ _ SelfSim) mu th_state1 m1 th_state2 m2 /\
inject_sync_event mu event1 event2 /\
let angel2:= inject_virtue m2 mu angel in
let st2':= fullThUpd_comp st2 tid cnt2 (Kresume sum_state2 Vundef)
angel2 (b', unsigned (add ofs (repr delt))) in
syncStep(Sem:=HybridSem (Some (S hb))) true cnt2 Hcmpt2 st2' m2' event2.