Definition lockSet_Writable (lset : lockMap) m :=
forall b ofs, AMap.find (b,ofs) lset ->
forall ofs0, Intv.In ofs0 (ofs, ofs + LKSIZE)%Z ->
Mem.perm_order'' ((Mem.mem_access m)!! b ofs0 Max) (Some Writable) .
(*This definition makes no sense. In fact if there is at least one lock in rmap, *then the locks_writable is false (because perm_of_res(LK) = Some Nonempty). *)
Definition locks_writable (juice: rmap):=
forall loc sh psh P z i, juice @ loc = YES sh psh (LK z i) P  ->
Mem.perm_order'' (perm_of_res (juice @ loc)) (Some Writable).
Record mem_compatible_with' (tp : thread_pool) m all_juice : Prop :=
{   juice_join : join_all tp all_juice
; all_cohere : mem_cohere' m all_juice
; loc_writable : lockSet_Writable (lockGuts tp) m
; jloc_in_set : juicyLocks_in_lockSet (lockGuts tp) all_juice
; lset_in_juice: lockSet_in_juicyLocks  (lockGuts tp) all_juice
}.
Definition mem_compatible_with := mem_compatible_with'.
Definition mem_compatible tp m := ex (mem_compatible_with tp m).

(* Specifications: *)
Lemma jlocinset_lr_valid: forall ls juice,
lockSet_in_juicyLocks ls juice ->
lr_valid (AMap.find (elt:=lock_info)^~ (ls)).
Lemma compat_lr_valid: forall js m,
mem_compatible js m ->
lr_valid (lockRes js).
Lemma mem_compatible_locks_ltwritable':
forall js m, lockSet_Writable (lockGuts js) m ->
permMapLt (lockSet js) (getMaxPerm m ).
Lemma mem_compatible_locks_ltwritable:
forall tp m, mem_compatible tp m ->
permMapLt (lockSet tp) (getMaxPerm m ).