Program Fixpoint find_thread' {st:t}{filter:ctl -> bool} n (P: n < num_threads st) {struct n}:=
      if filter (@pool st (@Ordinal (num_threads st) n P))
      then Some n
      else match n with
           | S n' =>  find_thread' n' (lt_decr  n' _ P)
           | O => None
           end.Definition pos_pred (n:pos): nat.Program Definition find_thread (st:t)(filter:ctl -> bool): option tid:=
      @find_thread' st filter (pos_pred (num_threads st)) _ .(* Definition containsThread_dec (tp : t) (i : NatTID.tid) : bool:=
  Compare.Pcompare i (num_threads tp). *)
    Definition containsThread (tp : t) (i : NatTID.tid) : Prop:=
      i < num_threads tp.Definition containsThread_dec:
      forall i tp, {containsThread tp i} + { ~ containsThread tp i}.Definition getThreadC {i tp} (cnt: containsThread tp i) : ctl :=
      tp (Ordinal cnt).Definition unique_Krun' tp i :=
      ( forall j cnti q,
          @getThreadC j tp cnti = Krun q ->
          eq_nat_dec i j ).Definition is_running tp i:=
      exists cnti q, @getThreadC i tp cnti = Krun q.

(* Specifications: *)
Lemma unique_runing_not_running: forall tp i, unique_Krun' tp i -> ~ is_running tp i -> forall j, unique_Krun' tp j.