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) .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
      }.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
      }.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
      }.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
      }.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
      }.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 ).
Lemma compat_lt_m: forall m js, mem_compatible js m -> forall b ofs, Mem.perm_order'' ((getMaxPerm m) !! b ofs) ((lockSet js) !! b ofs).
Lemma compatible_lockRes_join: forall (js : thread_pool) (m : mem), mem_compatible js m -> forall (l1 l2 : address) (R1 R2 : mpred) (phi1 phi2 : rmap), l1 <> l2 -> ThreadPool.lockRes js l1 = Some (R1, Some phi1) -> ThreadPool.lockRes js l2 = Some (R2, Some phi2) -> joins phi1 phi2.
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 ).
Lemma compat_lt_m: forall m js, mem_compatible js m -> forall b ofs, Mem.perm_order'' ((getMaxPerm m) !! b ofs) ((lockSet js) !! b ofs).
Lemma compatible_lockRes_join: forall (js : thread_pool) (m : mem), mem_compatible js m -> forall (l1 l2 : address) (phi1 phi2 : rmap), l1 <> l2 -> ThreadPool.lockRes js l1 = Some (Some phi1) -> ThreadPool.lockRes js l2 = Some (Some phi2) -> joins phi1 phi2.