Example #1
0
int main (int argc, char **argv)
{
  char  *work_dir;
  
  init_procs (&argc, &argv);                          /* Initialization */
  num_proc = proc_num ();                             /* Number of procs */
  n_proc   = proc_id  ();                             /* Proc id */

  work_dir = argv[1];                                 /* Work directory */
 
  if(argc == 1)
    work_dir=".";
 
  if (n_proc == 0)
  {
    fprintf (stdout, "Running on %d processors\n", num_proc);
    fflush  (stdout);
  }
  
  double start = wclock();
  
  driver (work_dir);

  double finish = wclock();
  
  fini_procs ();                                      /* Wrap up */
  
  fprintf (stdout, "Elapsed time on proc %3d: %le (%le %le)\n", 
           n_proc, finish-start, start, finish);
  fflush  (stdout);

  return (0);
}
Example #2
0
/* REPL */
int main() {
    atexit(on_exit);
    init();

    global_environment = setup_environment();
    init_procs(global_environment);

    printf("Welcome to BoboScheme\nUse ctrl-c to exit.\n");

    write(load_file("src/stdlib.scm"));
    printf("\n");

    while(1) {
        printf("> ");
        object_t *r = read(stdin);
        if(!isemptylist(r)) {
            write(eval( r, global_environment ));
        } else {
            // Ctrl+D
            exit(0);
        }
        printf("\n");
    }

    return 0;
}
Example #3
0
int
main()
{
  uint32_t quantum;
  context_t context;

  /* Read quantum */
  printf("Enter quantum : ");
  scanf("%u", &quantum);

  /* Init context_t */
  if (init_procs(&context) == -1) {
    printf("Can't init procs, program will be closed.\n");
    return (1);
  }

  /* Start execution */
  perf_times perfs;
  init_perf_struct(&perfs);

  uint32_t nb_remain = context.n,
           cur_time = context.procs[0].arrival_time, /* cur_time is initialized to first arrival time */
           i = 0; /* Index of executing process */

  enqueue_arriving_processes(&context, cur_time);

  /* Run till all processes end */
  while (nb_remain != 0) {
    /* If the queue is empty, and there's still remaining processes,
       we move time forward to the next arriving process */
    if (queue_empty(&context.p_queue)) {
      cur_time = context.procs[context.next_arrive_proc].arrival_time;
      enqueue_arriving_processes(&context, cur_time);
    }

    i = dequeue(&context.p_queue);

    /* This is the end of the process */
    if (context.procs[i].remain_time <= quantum) {
      cur_time += context.procs[i].remain_time;
      context.procs[i].remain_time = 0;

      perfs.turn_around += (cur_time - context.procs[i].arrival_time);
      perfs.wait_time += (cur_time - context.procs[i].arrival_time - context.procs[i].burst_time);

      nb_remain--;

      printf("%d- Ended at %d.\n", context.procs[i].id, cur_time);
    }

    /* Execute till the end of the quantum */
    else {
      context.procs[i].remain_time -= quantum;
      cur_time += quantum;

      enqueue(&context.p_queue, i);

      printf("%d- Preempted at %d\n", context.procs[i].id, cur_time);
    }

    /* Maybe we have arriving processes */
    if (context.next_arrive_proc < context.n)
      enqueue_arriving_processes(&context, cur_time);
  }

  printf("\nAverage turn around : %d\n", perfs.turn_around / context.n);
  printf("Average wait time : %d\n", perfs.wait_time / context.n);

  free_procs(&context);
  return (0);
}