1 Crore+ students have signed up on EduRev. Have you? |
Implementation of ________ may waste CPU cycles.
Spinlock: It is also called Busy Waiting. It is a process synchronization technique that makes the process (task) wait for a particular operation to complete or check for a condition to satisfy before proceeding with its execution.
Sleep and Wake: It is a very simple concept where a process that wants to enter into the critical section but the critical section is busy then the process will go to sleep. It will be woken by the other process which is currently in the critical section so that the sleeping process can wake up and enter into the critical section. This process is done to prevent the wastage of CPU cycles.
Busy Waiting in process synchronisation is a term used when a process is in critical section and other processes are waiting to enter critical section. Busy Waiting is also called ___________
Bounded Waiting: This is a condition that needs to be fulfilled to achieve synchronisation.
Busy processing: There is no such thing as busy processing.
Spin Lock: Also called Busy Waiting.
Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.
The processes are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of D after the three processes have completed execution are X and Y respectively, then the value of Y - X is __________.
Maximum value (Y):
Minimum value (X):
At a particular time of computation the value of a counting semaphore is 7. Then 20 P operations and 15 V operation were completed on this semaphore. The resulting value of the semaphore is
Concepts:
V(S): Signal operation will increment the semaphore variable, that is, S++.
P(S): Wait operation will decrement the semaphore variable., that is, S--.
Data:
Initial counting semaphore = I = 7
Wait operation = 20 P
Signal operation = 15 V
Final counting semaphore = F
Formula:
F = I + 15V + 20P
Calculation:
F = 7 + 15(+1) + 20(-1)
∴ F = 2
the resulting value of the semaphore is 2
Which of the following is not an optimization criterion in the design of a CPU scheduling algorithm?
Maximum CPU utilization, maximum throughput, minimum turnaround time, and Minimum waiting time are the optimization criterion in the design of a CPU scheduling algorithm
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.
The number of distinct values that B can possibly take after the execution is __________.
Initial value of B is 2 //value stored in main memory
Value of B = 4
First execute P2()
P2 ( ) {
D = 2 * B; // 2 × 2 = 4
B = D – 1; // B = 4 – 1 = 3
}
write the value of B = 3 to memory
execute P1()
P1 ( ) {
C = B – 1; // C = 3 – 1 = 2
B = 2 * C; // B = 2 × 2 = 4
}
write the value of B = 4 is memory.
Distinct value of B is 4.
Value of B =3
First Execute P1()
P1 ( ) {
C = B – 1; // C = 2 – 1 = 1
B = 2 * C; // B = 2 × 1 =2
}
write the value of B = 2 to memory
then execute P2()
P2 ( ) {
D = 2 * B; // 2 × 2 = 4
B = D – 1; // B = 4 – 1 = 3
}
write the value of B = 3 to memory
One of the distinct values of B is 3.
Value of B = 2
First execute P2()
P2 ( ) {
D = 2 * B; // 2 × 2 = 4
B = D – 1; // B = 4 – 1 = 3
}
//don’t write to memory
execute P1() // with initial value of B = 2
P1 ( ) {
C = B – 1; // C = 2 – 1 = 1
B = 2 * C; // B = 2 × 1 = 2
}
write the value B = 3 by P2() in memory.
overwrite the value written by P2() as B = 2 by P1() in memory.
One of the distinct values of B is 2.
Therefore, the distinct values of B are 2, 3 and 4.
The number of distinct values that B can possibly take after the execution is 3.
Semaphores: It is a non-negative integer value used by various processes mutually exclusive to achieve synchronization. A semaphore S can be accessed by only two operations which are atomic and mutually exclusive in nature - Wait (P) and Signal (V). There are two types of semaphores:
Monitor: It is a high-level construct implemented using a programming language that packages the data and procedures to modify the data. Only one processor is allowed in the monitor at a time.
Mutex: It is a locking mechanism used to synchronize access to a resource. Only one task can acquire the mutex, hence, ownership is associated with mutex and only the owner can release the lock. This whole system can be implemented using a binary semaphore hence, it is referred to as a binary semaphore.
Consider a counting Semaphore variable 'S'. Following are the semaphore operations performed: 18P, 3V, 7V, 2P, 6V. What can be the largest initial value of S to keep one process in suspended list?
Semaphore: it is an integer variable which is used by different processes in a mutually exclusive manner so as to achieve synchronisation.
There are two types of Semaphores:
There are two types of operations that are atomic and mutually exclusive in nature:
Calculations:
The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0.
How many times will process P0 print ‘0’?
Concept:
Binary semaphore which can take only two values 0 and 1 and ensure mutual exclusion.
A process is entered into the critical section only when the value of semaphore(s) = 1
Otherwise, it will wait until semaphore(s) >0
The semaphores are initialized as S0=1, S1=0, S2=0.
Because S0 =1 then P0 enter into the critical section and other processes will wait until either S1=1 or S2 =1
The minimum number of times 0 printed:
The minimum number of time 0 printed is twice when executing in this order (p0 -> p1 -> p2 -> p0)
The Maximum number of times 0 printed:
Maximum no. of time 0 printed is thrice when execute in this order (p0 -> p1 -> p0 -> p2 -> p0)
So, At least twice will process P0 print ‘0’
Two atomic operations permissible on Semaphores are __________ and __________.
Semaphores are integer variables that are used to solve the critical section problem by using two atomic operations, wait and signal that are used for process synchronization.
Wait:
The wait operation decrements the value of its argument S if it is positive. If S is negative or zero, then no operation is performed.
wait(S)
{
while (S<=0)
S--;
}
Signal:
The signal operation increments the value of its argument S.
signal(S)
{
S++;
}
80 docs|33 tests
|
Use Code STAYHOME200 and get INR 200 additional OFF
|
Use Coupon Code |
80 docs|33 tests
|
|
|
|
|
|
|
|