Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please with out put to make sure it is correct .. Part 3 Write a C program using

ID: 3677015 • Letter: P

Question

Please with out put to make sure it is correct ..

Part 3 Write a C program using Pthreads and a circular queue to simulate the round-robin scheduling algorithm as follows: The program is to be called round_robin.c and it works only with 5 processes, P_1, P_2, P_3, P_4, and P_5 To simulate work for each P_i, use C's sleep() function To run your program, pass the desired quantum along with 5 burst times, one for each of the 5 processes (Pi through P5) in the circular ready queue. Your program should take inputs and output a table (based on Gantt chart) as shown below:

Explanation / Answer

#include #include #include double times[5]; char process[] = {'A', 'B', 'C', 'D', 'E'}; int turn = 0; void StartNext(int tid) //choose the next thread to run { int i; for(i = (tid + 1) % 5; times[i] == 0; i = (i + 1) % 5) if(i == tid) //if every thread has finished return; turn = i; } void *Run(void *tid) //the thread function { int i = (int)tid; while(times[i] != 0) { while(turn != i); //busy waiting till it is its turn if(times[i] > 2) { printf("%c 2 ", process[i]); sleep(2); //sleep is to simulate the actual running time times[i] -= 2; } else if(times[i] > 0 && times[i]