In Multiprogramming, there are two kinds of processes. One is independent processes and the another one is cooperative processes. Independent processes are independent of each other, but cooperative processes can affect or affected by other processes executing in the system. They share logical address space or data through files or messages. Concurrent access to the shared data by the cooperating processes can result into data inconsistency.
For example, we can take race condition when several processes access and manipulate the same data concurrently and the outcome varies with the particular order in which access takes place.
Consider the following processes.
initially, count=5
P1 P2
count++ count--;
The increment or decrement of count inside the processor happens as follows:
P1 P 2
R1<=count R2<=count
R1<=count+1 R2<=count-1
count<=R1 count<=R2
Consider the following sequence of the steps,
R1<=count R1=5
R1<=R1+1 R1=6
R2<=count R2=5
R2<=R2-1 R2=4
count<=R2 count=4
count<=R1 count=6
The final output will be either 4 or 6 depending on which process will execute it's final step last. But, You can see that the actual answer should be 5. Thus, both the processes are racing with each other to manipulate the final result. This is known as race condition.
To avoid these kind of situations, we require Process Synchronization.
THE CRITICAL SECTION PROBLEM:
The critical section is the part of code of the cooperative processes which involves changing common variables or accessing shared resources.
If one process is executing in its critical section, no other process is allowed to enter into critical section. There are some protocols designed regarding critical section which every process must follow. Each process must request permission to enter it's critical section. The section of code implementing this request is called entry section. After passing through entry section, a process enters the critical section and then followed by a exit section. The remaining code of the process is known as remainder section.
There are several solutions are designed for this critical solution problem. But every solution must satisfy the following requirements.
1) Mutual exclusion: If one process is executing in it's critical section, then no other process can enter it's critical section.
2) Progress: If no process is executing in it's critical section, and some processes want to enter in their critical section, then only those who are not in their remainder section can participate to decide who will enter the critical section next.
3) Bounded Waiting: There will be a limit on the umber of times that other processes are allowed to enter their critical section when a process made a request to enter it's critical section and before that request is granted.
SOLUTIONS OF CRITICAL SECTION PROBLEM:
1) Peterson's solution.
2) Mutex Locks.
3) Test and set
2) compare and swap.
4) Semaphores.
0 Comments