on task creation:
^^^^^^^^^^^^^^^^

  th->missed_deadline = 0;
  th->num_missed_deadlines = 0;
  th->total_time_so_far = 0;
  th->deadline = INFINITE;
  th->preempted = 0;
  th->done = 0;
  th->arrival_time = 0;

on task being preempted:
^^^^^^^^^^^^^^^^^^^^^^^

  current_time = TIME;
  if ( current_time > deadline && th->missed_deadline == 0 ) {
     deadline_missed = 1;
     th->num_missed_deadlines++;
     th->missed_deadline = 1;
  }
  time_so_far = current_time - th->last_resched;
  if ( done ) {
    th->total_time_so_far = 0;
    th->done = 0;
    th->preempted = 0;
  }
  else {
    th->preempted = 1;
  }

on task selected for execution:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  current_time = TIME;
  th->last_reschedule = current_time;
  if ( th->preempted == 1 ) {
    th->total_time_so_far = current_time - last_resched;
  }
  else {
    if ( done == 0 ) {
      if ( th->arrival_time == 0 ) {
        th->arrival_time = TIME;
        th->deadline = th->arrival_time + th->deadline;
        th->next_arrival = th->arrival_time + th->period;
      }
      th->total_time_so_far = 0;
    }
  }

on task wake up:
^^^^^^^^^^^^^^^

  if ( th->next_arrival == TIME || th->missed_deadline == 1 ) {
    if ( th->missed_deadline == 1 ) {
      th->missed_deadline = 0;
    }
    else {
      th->arrival_time = TIME;
      th->next_arrival = TIME + period;
      if ( th->done ) { 
        th->deadline = TIME + deadline;
      }
    }
  }
