Documente Academic
Documente Profesional
Documente Cultură
Multiple threads will enter into the user function and all threads that come after the first one will wait
until it either runs for the time quantum or it finishes its burst.
This will continue until all of the bursts are completed.
Analysis of the Algorithm:
This algorithm works. It runs for the correct amount of time and produces the correct output.
Description:
This program creates a scheduler for user-level threads using a Round Robin (RR) scheduling
algorithm. A controller creates as many threads as input by the user,
then uses a timer that interrupts the scheduler at predetermined intervals, also set by the user, and
switches the currently running thread to the thread in the front of the waiting queue.
The user input for this program is entered in the form of ./scheduling <number of threads> <length of
time quantum in seconds>
Input:
@x:~$ ./scheduling 3 5
Burst time for thread 0: 8
Burst time for thread 1: 9
Burst time for thread 2: 12
Output:
Thread 0 is now being executed
1
2
3
4
5
Thread 1 is now being executed
6
7
8
9
10
Thread 2 is now being executed
11
12
13
14
15
{
printf("Thread %d finished its job. It will be terminated\n",id);//finish
curThr[id]=1;
count++;
break;
}
}
pthread_mutex_unlock(&lock);//lock and access critical section
}
}