Mutual Exclusion of Processes





Mutual exclusion is a mechanism to ensure that only one process is doing certain things at one time and other are prevented from modification shared data until the current process finish.
*Implementation of mutual exclusion
Let us consider an example of “too much pizza” problem
There are the process A & B having schedule as shown in figure below.

Proceees Schedule

Proceees Schedule

This problem shows that when co-operating processes are not synchronised, they may face unexpected error.  Mutual exclusion mechanism when applied to this problem will ensure that only one person buys pizza at a time.

Solution 1:
It is assumed that a note can be put by either of them to indicate that they are leaving to store to buy pizza.

For process A & B

If (no pizza)
{
If (no note)
{
Leave note;
Buy pizza;
Remove note;
}
}
Solution 2:

Process A

Leave note A;
If (no note B)
{
If (no pizza)
{
Buy pizza;
}
}

Process B:

Leave note B;
If (no note A)
{
If (no pizza)
{
Buy pizza;
}
}
Solution-2 can leave the two processes in a state where both the processes if leave their own notes simultaneously, then their “a” statement will return false and thus none of them will be able to execute its instruction for buying pizza.
Solution -3:
Process A:
Leave note A;
If (no note B)
{
If (no pizza)
{
Buy pizza
}
}
Remove note A;

Process B:
Leave note B;
While (note A)
{
; // do nothing
}
If (no pizza)
{
Buy pizza;
}

Remove note B:
Solution-3 tends to leave process B in a state while it consume CPU cycle while waiting for its turn to execute the instruction following the while condition.
In any case the solution would be more complicated if extended too many processes. All these tree solution are obtained by implementing the mutual exclusion mechanism.
Some important terms:-
1. Lock: – the technique most often used for serialising resources is to “cock” these resources. The state of the lock determines whether the resource is concurrently in use by a process. The simplest case of lock is a bit that is a set to 1 when a resource is in case & set to 0, when the resource is not in use. No process can use a resource as long as the lock for that process is set. Only when the first process has completed its use of the resource does it release the lock and allow other process to use that resource.
2. Throughput: – The number of job done per unit time period is called throughput. It always our need for increasing the CPU utilisation. Actually, it is used for measuring of performance.



Related posts:

  1. Introduction to Processes in operating system   Early computer system allowed any one program to be...
  2. Introduction to operating system Operating System: An operating system is a collection of system...
  3. supervisor and user mode of operating system supervisor and user mode: The process is executed in the...
  4. Process States As the program executes, it generally changes state. A state...
  5. What is kernel? Kernel: All the operating involving processes are controlled by a...