Local Arguments getThreadR {_} {_} {_} _ _ _.
Local Arguments getThreadC {_} {_} {_} _ _ _.
Local Arguments personal_mem : clear implicits.
Local Arguments updThread {_} {_} {_} _ _ _ _ _.
Local Arguments updThreadR {_} {_} {_} _ _ _ _.
Local Arguments updThreadC {_} {_} {_} _ _ _ _.
Local Arguments juicyRestrict : clear implicits.
Set Bullet Behavior "Strict Subproofs".
(*Lemma mem_cohere_age_to_inv n m phi : mem_cohere' m (age_to n phi) -> mem_cohere' m phi.  Lemma mem_cohere_step c c' jm jm' Phi (X : rmap) ge : mem_cohere' (m_dry jm) Phi -> sepalg.join (m_phi jm) X Phi -> corestep (juicy_core_sem (cl_core_sem ge)) c jm c' jm' -> exists Phi', sepalg.join (m_phi jm') (age_to (level (m_phi jm')) X) Phi' /\ mem_cohere' (m_dry jm') Phi'.  (** About lock_coherence *)
Ltac jmstep_inv :=
match goal with
| H : JuicyMachine.start_thread _ _ _ _  |- _ => inversion H
| H : JuicyMachine.resume_thread _ _ _   |- _ => inversion H
| H : JuicyMachine.threadStep _ _ _ _ _           |- _ => inversion H
| H : JuicyMachine.suspend_thread _ _ _ |- _ => inversion H
| H : JuicyMachine.syncStep _ _ _ _ _ _           |- _ => inversion H
(*  | H : JuicyMachine.threadHalted _                   |- _ => inversion H*)
| H : JuicyMachine.schedfail _         |- _ => inversion H
end; try subst.
Ltac getThread_inv :=
match goal with
| [ H : getThreadC ?i _ _ = _ ,
H2 : getThreadC ?i _ _ = _ |- _ ] =>
pose proof (getThreadC_fun _ _ _ _ _ _ _ H H2)
| [ H : getThreadR ?i _ _ = _ ,
H2 : getThreadR ?i _ _ = _ |- _ ] =>
pose proof (getThreadR_fun _ _ _ _ _ _ _ H H2)
end.
Ltac substwith x y := assert (x = y) by apply proof_irr; subst x.

Lemma lockSet_Writable_updThread_updLockSet ge m m' i (tp : jstate ge)
b ofs ophi ophi' c' phi' z cnti
(Hcmpt : mem_compatible tp m)
(His_unlocked : AMap.find (elt:=option rmap) (b, Ptrofs.intval ofs) (lset tp) = Some ophi)
(Hlt' : permMapLt
(setPermBlock (Some Writable) b (Ptrofs.intval ofs) (juice2Perm_locks (getThreadR i tp cnti) m)
LKSIZE_nat) (getMaxPerm m))
(Hstore : Mem.store Mint32 (restrPermMap Hlt') b (Ptrofs.intval ofs) (Vint z) = Some m') :
lockSet_Writable (lset (updThread i (updLockSet tp (b, Ptrofs.intval ofs) ophi') cnti c' phi')) m'.