/*
	Runtime Engine
		By Craig Kadziolka ( Nov 1999 - Dec 2000 )

	Modifications and copying is permitted providing this header
	is retained
*/

#include "tasks.h"
#include "Threads.h"
#include "events.h"

#define NO_THREADS 100
#define NO_ITERS 1000

long int subtasks = NO_THREADS;

void Init()
{
  /* Distributed specific initialization */
}

void subtask()
{
  int a = 0;

 subtask_loop:
  
  a++;
  
  if (a == NO_ITERS) {
    subtasks--;
    return;
  }

  //  write(1, "S\n", 2);

  Suspend();

  goto subtask_loop;
  
}

void Task_one()
{

  long int godzilla;

 tone:

  //  printf("Subtasks Active: %d \n", subtasks);


  if (subtasks == 0) {
    printf("All subtasks have died!\n");
    return;
  }
  
  Suspend();

  goto tone;

}

int Main()
{

  long int godzilla = 0;

  disable_interrupts();

  for (godzilla = 0; godzilla < NO_THREADS; godzilla ++) {

    Create_Thread(1, 0, subtask);

  }

  enable_interrupts();

  Task_one();
  
}
