Critical Section and Mutual Exclusion:
What is Critical Section or Critical Region? :
That part of the program where the shared memory is accessed is called critical section.To avoid race condition we need mutual exclusion.
Mutual Exclusion: It is some way of making sure that if one process is using a shared variable or file, the other process will be excluded from doing the somethings.
The difficulty in printer spooler occurs because process B started using one of the shared variables before process A was finished with it. If we could arrange matter such that no two processes were ever in there critical regions at at the same time, we could avoid race conditions.
Solution to Critical Section Problem:
•1) no two processes maybe simultaneously inside their critical regions.
•2) no assumptions may be made about speed or the number of CPUs.
•3) no process running outside a critical region may block other processes.
•4) no process should have to wait forever to enter its critical regions.
Example : Process A enters its critical region at time Tj. A little later, at time T1, Process B attempt to enter its critical region. But fails because another process is already in its critical region any we allow one at a time only. Consequently, B is temporary suspend until process leave the critical region. After Process A leaves the critical region, process B enters the critical region.
18- Interprocess Communication- Critical Sections & Mutual Exclusion
CLICK HERE TO Download This PDF NOTES