#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/times.h>
#define SLOTX 4
#define CYCLEX 5
#define SLOT_T 5000

int tps,cycle=0,slot=0;
clock_t now, then;
struct tms n;

void one() {
  printf("Task 1 running\n");
  sleep(1);
}


void two() {
  printf("Task 2 running\n");
  sleep(1);
}

void three() {
  printf("Task 3 running\n");
  sleep(1);
}

void four() {
  printf("Task 4 running\n");
  sleep(1);
}

void five() {
  printf("Task 5 running\n");
  sleep(1);
}

void burn() {
  
  clock_t bstart = times(&n);
  

  while ((( now = times(&n)) - then) < SLOT_T * tps / 1000) {
   
  }

  printf (" brn time = %2.2dms\n\n", (times(&n)-bstart)*1000/tps);
	  then = now;
	  cycle = CYCLEX;
}
void (*ttable[SLOTX][CYCLEX])() = {
{one, two, burn, burn, burn},
{one, three, four, burn, burn},
{one, two, burn, burn, burn},
{one, five, four, burn, burn}};
 
main() {
    tps = sysconf(_SC_CLK_TCK);
    printf("clock ticks/sec = %d\n\n", tps);
    then = times(&n);
    while (1) {
      for (slot=0; slot <SLOTX; slot++)
	for (cycle=0; cycle<CYCLEX; cycle++)
	  (*ttable[slot][cycle])();
    }
  }        
