Definition mem_ok (tp: dryThreadPool) m :=
Smallstep.globals_not_fresh (Clight.genv_genv ge) m /\
mem_wd2 m /\
(forall i (CT: containsThread tp i),
ctl_ok (Mem.nextblock m) (getThreadC CT)).

(* Specifications: *)
Lemma mem_ok_wd: forall tp m, mem_ok tp m -> Mem.mem_wd m.
Lemma mem_ok_restr: forall tp m p Hlt, mem_ok tp m -> mem_ok tp (@restrPermMap p m Hlt).
Lemma ctl_ok_updThread:
forall nextb (ms: dryThreadPool) tid c r
(H: containsThread ms tid),
ctl_ok nextb c ->
(forall i (CT: containsThread ms i), ctl_ok nextb (getThreadC CT)) ->
(forall i (CT: containsThread (updThread H c r) i),
ctl_ok nextb (getThreadC CT)).
Lemma ctl_ok_updLockSet:
forall nextb (ms: dryThreadPool) tid x r
(H: containsThread ms tid),
(forall i (CT: containsThread ms i), ctl_ok nextb (getThreadC CT)) ->
(forall i (CT: containsThread (updLockSet ms x r) i),
ctl_ok nextb (getThreadC CT)).
Lemma ctl_ok_remLockSet:
forall nextb (ms: dryThreadPool) tid x
(H: containsThread ms tid),
(forall i (CT: containsThread ms i), ctl_ok nextb (getThreadC CT)) ->
(forall i (CT: containsThread (remLockSet ms x) i),
ctl_ok nextb (getThreadC CT)).
Lemma ctl_ok_updThreadC:
forall nextb (ms: dryThreadPool) tid c
(H: containsThread ms tid),
ctl_ok nextb c ->
(forall i (CT: containsThread ms i), ctl_ok nextb (getThreadC CT)) ->
(forall i (CT: containsThread (updThreadC H c) i),
ctl_ok nextb (getThreadC CT)).
Lemma ctl_ok_addThread:
forall nextb (ms: dryThreadPool) tid v1 v2 r
(H: containsThread ms tid),
val_ok nextb v1 ->
val_ok nextb v2 ->
(forall i (CT: containsThread ms i), ctl_ok nextb (getThreadC CT)) ->
(forall i (CT: containsThread (addThread ms v1 v2 r) i),
ctl_ok nextb (getThreadC CT)).
Lemma mem_ok_threadStep:
forall
(ms : dryThreadPool) (m : mem) (tid : nat)
(m' : mem) (ev : list mem_event)
(Hmem : mem_ok ms m)
(Htid : containsThread ms tid)
(Hcmpt : mem_compatible ms m)
(c c': Clight_new.corestate)
(Hcode : getThreadC Htid = Krun c)
(Hcorestep : cl_evstep ge c (restrPermMap (proj1 (Hcmpt tid Htid))) ev c' m'),
mem_ok (updThread Htid (Krun c') (getCurPerm m', snd (getThreadR Htid))) m'.
Lemma mem_ok_step: forall st m st' m' (Hmem: mem_ok (threadpool_of st) m),
MachStep(Sem := Clight_newSem ge)
(ThreadPool:= OrdinalPool.OrdinalThreadPool)
(machineSig:= HybridMachine.DryHybridMachine.DryHybridMachineSig)
st m st' m' ->
mem_ok (threadpool_of st') m'.