Professional Documents
Culture Documents
Assignment 2
Submitted By Group:
Names: Muhammad Haseeb,
Rida e Noor Gillani,
Warisha Altaf.
Reg No.: FA20-BCS-053,
FA20-BCS-078,
FA20-BCS-093.
Date of Submission:
24th April, 2022
Submitted To:
Ma’am Memoona Malik
BCS – IV
Assignment 2 Marks: 15
P1 9 0
P2 7 2
P3 4 3
P4 5 5
P5 3 6
SJF Preemptive:
Gantt Chart:
P1 P2 P3 P5 P4 P2 P1
0 2 3 7 10 15 21 28
Waiting Time for Each Process:
P1:
= [(0-0) + (21-2)]
=19
P2:
= [(2-2) +(15-3)]
=12
P3:
= (3-3)
=0
P4:
= (10-5)
=5
P5:
= (7-6)
=1
Average waiting time:
= {[(0-0) + (21-2)] + [(2-2) +(15-3)] + (3-3) + (10-5) + (7-6)} /5
= (19 + 12 + 0 + 5 + 1) / 5
= 37 / 5
= 7.4
Turn Around Time for Each Process:
P1:
= 28
P2:
=21
P3:
=7
P4:
= 15
P5:
= 10
Average Turnaround time:
= (28 + 21 + 7 + 15 + 10) / 5
= 16.2
Round Robin:
Time quantum = 3
Gantt Chart:
P1 P2 P3 P4 P5 P1 P2 P3 P4 P1 P2
0 3 6 9 12 15 18 21 22 24 27 28
Waiting Time for Each Process:
P1:
= [(0-0) + (15-3) + (24-18)]
= 18
P2:
= [(3-0) +(18-6) +(27-21)]
= 21
P3:
= [(6-0) + (21-9)]
= 18
P4:
= [(9-0) + (22-12)]
= 19
P5:
= (12-0)
= 12
Average waiting time:
= {[(0-0) + (15-3) + (24-18)] + [(3-0) +(18-6) +(27-21)] + [(6-0) + (21-9)] +[(9-0)
+ (22-12)] + (12-0)} /5
= (18 + 21 + 18 + 19 + 12) / 5
= 88 / 5
= 17.6
Turn Around Time for Each Process:
P1:
= 27
P2:
=28
P3:
= 22
P4:
= 24
P5:
= 15
Average Turnaround time:
= (27 + 28 + 22 + 24 + 15) / 5
= 23.2
Q3) How Readers-writer problem can be solved using mutex locks and semaphores? [5]
The reader-writers problem is related to process synchronization. The problems in data set occur
when the file is shared between more than one process at a time.
Mutex Lock:
A mutex is a locking mechanism which is used to synchronize the access to a resource to protect
the critical section. During the execution of multiple processes, only one task can acquire the
mutex. It means that there is an ownership associated with mutex. The thread which has the
access the mutex can only lock or unlock the mutex.
Mutex is used when the thread does not want any other thread to execute the critical section.
Whenever a thread gets the access of the mutex, the following steps occur:
For a thread named as Thread-1
1) Wait(mutex)
2) >>>enter into critical section
3) Signal(mutex)
A mutex object allows one thread into the critical section while the other threads have to wait for
their turn. If the mutex is occupied but the other thread tries to enter the mutex then an error will
occur.
Semaphore:
The semaphore is a signaling mechanism. It restricts the number of users sharing critical section
simultaneously. Multiple threads can request access to the resource which will decrement the
semaphore occupied space and when the operation is complete, the thread gives signal which
will increment the semaphore value.
So, readers-writers’ problems can be solved using these two mechanisms.