/* * main() simply parses command line arguments, then calls start_simulator(). * You will need to modify it to support the -r and -p command-line parameters. */ int main(int argc, char *argv[]) { int cpu_count; /* Parse command-line arguments */ if (argc != 2) { fprintf(stderr, "CS 425 Project 3 -- Multithreaded OS Simulator\n" "Usage: ./os-sim <# CPUs> [ -r <time slice> ]\n" " Default : FIFO Scheduler\n" " -r : Round-Robin Scheduler\n"); return -1; } cpu_count = atoi(argv[1]); /* FIX ME - Add support for -r and -p parameters*/ /* Allocate the current[] array and its mutex */ current = malloc(sizeof(pcb_t*) * cpu_count); assert(current != NULL); pthread_mutex_init(¤t_mutex, NULL); /* Start the simulator in the library */ start_simulator(cpu_count); return 0; }
int main(int argc, char *argv[]) { int timeout_interval, pkt_loss, garbled, debug_flags; long event; if (!parse_first_five_parameters(argc, argv, &event, &timeout_interval, &pkt_loss, &garbled, &debug_flags)) { printf ("Usage: p3 events timeout loss cksum debug\n"); exit(1); } printf("\n\n Simulating Protocol 3\n"); start_simulator(sender3, receiver3, event, timeout_interval, pkt_loss, garbled, debug_flags); }
/* * main() simply parses command line arguments, then calls start_simulator(). * You will need to modify it to support the -r and -p command-line parameters. */ int main(int argc, char *argv[]) { int opt; /* Parse command-line arguments */ if (argc > 5) { fprintf(stderr, "CS 2200 Project 4 -- Multithreaded OS Simulator\n" "Usage: ./os-sim <# CPUs> [ -r <time slice> | -p ]\n" " Default : FIFO Scheduler\n" " -r : Round-Robin Scheduler\n" " -p : Static Priority Scheduler\n\n"); return -1; } cpu_count = atoi(argv[1]); // parse cmd line options while ((opt = getopt(argc, argv, "r:p")) != -1) { switch (opt) { case 'r': use_round_robin = 1; time_slice = strtol(optarg, NULL, 10); break; case 'p': use_priority = 1; break; default: break; } } /* Allocate the current[] array and its mutex */ current = malloc(sizeof(pcb_t*) * cpu_count); assert(current != NULL); // allocate space for locks and condition vars current_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); ready_q_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); idle_cond = (pthread_cond_t *) malloc(sizeof(pthread_cond_t)); // initalize locks and cond vars pthread_mutex_init(current_mutex, NULL); pthread_mutex_init(ready_q_mutex, NULL); pthread_cond_init(idle_cond, NULL); /* Start the simulator in the library */ start_simulator(cpu_count); return 0; }
/* * main() parses command line arguments, initializes globals, and starts * simulation */ int main(int argc, char* argv[]) { /* Parse command line args - must include num_cpus as first, rest optional * Default is to simulate using just FIFO on given num cpus, if 2nd arg given: * if -r, use round robin to schedule (must be 3rd arg of time_slice) * if -p, use static priority to schedule */ if (argc == 2) { alg = FIFO; printf("running with basic FIFO\n"); } else if (argc > 2 && strcmp(argv[2], "-r") == 0 && argc > 3) { alg = RoundRobin; time_slice = atoi(argv[3]); printf("running with round robin, time slice = %d\n", time_slice); } else if (argc > 2 && strcmp(argv[2], "-p") == 0) { alg = StaticPriority; printf("running with static priority\n"); } else { fprintf(stderr, "Usage: ./os-sim <# CPUs> [ -r <time slice> | -p ]\n" " Default : FIFO Scheduler\n" " -r : Round-Robin Scheduler (must also give time slice)\n" " -p : Static Priority Scheduler\n\n"); return -1; } fflush(stdout); /* atoi converts string to integer */ cpu_count = atoi(argv[1]); /* Allocate the current[] array and its mutex */ current = malloc(sizeof(pcb_t*) * cpu_count); int i; for (i = 0; i < cpu_count; i++) { current[i] = NULL; } assert(current != NULL); pthread_mutex_init(¤t_mutex, NULL); /* Initialize other necessary synch constructs */ pthread_mutex_init(&ready_mutex, NULL); pthread_cond_init(&ready_empty, NULL); /* Start the simulator in the library */ printf("starting simulator\n"); fflush(stdout); start_simulator(cpu_count); return 0; }
main (int argc, char *argv[]) { int timeout_interval, pkt_loss, garbled, debug_flags; long event; if (!parse_first_five_parameters(argc, argv, &event, &timeout_interval, &pkt_loss, &garbled, &debug_flags)) { printf ("Usage: p6 events timeout loss cksum debug\n"); exit(1); } init_max_seqnr(MAX_SEQ + 1); printf("\n\n Simulating Protocol 6\n"); start_simulator(protocol6, protocol6, event, timeout_interval, pkt_loss, garbled, debug_flags); }