finished?

This commit is contained in:
Rushil Umaretiya 2024-04-18 02:23:37 -04:00
parent 8ff32c5e8d
commit aca8171c39
No known key found for this signature in database
GPG Key ID: 4E8FAF9C926AF959

View File

@ -6,21 +6,46 @@
#include <stdlib.h>
void run_to_completion(task_struct* task) {
// TODO:
printf("Task %d ran for %d cycle(s).\n", task->pid, task->remaining_cycles);
task->remaining_cycles = 0;
printf("Task %d completed.\n", task->pid);
}
void run_with_quantum(task_struct* task, unsigned int quantum) {
// TODO:
if (task->remaining_cycles <= quantum) {
run_to_completion(task);
} else {
printf("Task %d ran for %d cycle(s).\n", task->pid, quantum);
task->remaining_cycles -= quantum;
}
}
void fcfs() {
// TODO:
while (get_task(0) != NULL) {
run_to_completion(remove_task(0));
}
}
void priority_queue(unsigned int quantum) {
// TODO:
min_heapify();
while (get_task(0) != NULL) {
task_struct* task = get_task(0);
run_with_quantum(task, quantum);
if (task->remaining_cycles > 0) {
remove_task(0);
}
min_heapify();
}
}
void round_robin(unsigned int quantum) {
// TODO:
while (get_task(0) != NULL) {
task_struct* task = get_task(1 % size());
run_with_quantum(task, quantum);
if (task->remaining_cycles == 0) {
remove_task(task->pid);
}
}
}