(*  Lemma threadStep_not_unhalts:
    forall g i tp m cnt cmpt tp' m' tr,
      @threadStep g i tp m cnt cmpt tp' m' tr ->
      forall j cnt cnt',
        (@threadHalted j tp cnt) ->
        (@threadHalted j tp' cnt') .
  Proof.
    intros; inversion H; inversion H0; subst.
    destruct (NatTID.eq_tid_dec i j).
    - subst j.
      eapply corestep_not_halted in Hcorestep.
      unfold halted, j_halted in Hcorestep; simpl in Hcorestep.
      unfold j_halted in Hcorestep.
      replace cnt1 with cnt in Hthread0 by apply cnt_irr.
      rewrite Hthread0 in Hthread; inversion Hthread;
      subst c0.
      rewrite Hcorestep in Hcant; inversion Hcant.
    - econstructor; eauto.
      Set Printing Implicit.
      rewrite gsoThreadCode; auto;
      erewrite <- age_getThreadCode; eauto.
  Qed.*)

    (* The initial machine has to be redefined.
       Right now its build by default with empty maps,
       but it should be built with the correct juice,
       corresponding to global variables, arguments
       and function specs. *)

    (*Lemma onePos: (0<1)%coq_nat. auto. Qed.*)
    Definition initial_machine rmap c:=
      mk
        (mkPos (le_n 1))
        (fun _ => (Krun c))
        (fun _ => rmap)
        (AMap.empty _).Definition init_mach rmap (m: mem) (tp:thread_pool) (v:val) (args:list val) : Prop :=
      exists c, initial_core the_sem 0 m c v args /\
        match rmap with Some rmap => tp = initial_machine rmap c | None => False end.

Lemma cnt_age_iff {js i n} : containsThread js i <-> containsThread (age_tp_to n js) i.