On the basis of synchronization, processes are categorized as one of the
following two types:
Independent Process : Execution of one process does not affects the
execution of other processes.
Cooperative Process : Execution of one process affects the execution of other processes.
Process synchronization problem arises in the case of Cooperative process also because resources are shared in Cooperative processes.
It is the task phenomenon of coordinating the execution of processes in such a way that no two processes can have access to the same shared data and resources.
- It is a procedure that is involved in order to preserve the appropriate order of execution of cooperative processes.
- In order to synchronize the processes, there are various synchronization mechanisms.
- Process Synchronization is mainly needed in a multi-process system when multiple processes are running together, and more than one processes try to gain access to the same shared resource or any data at the same time.
- When two or more co-operating processes are sharing the same resource which leads to inconsistence in system.
- At the time when more than one process is either executing the same code or accessing the same memory or any shared variable; In that condition, there is a possibility that the output or the value of the shared variable is wrong so for that purpose all the processes are doing the race to say that my output is correct. This condition is commonly known as a race condition.
- As several processes access and process the manipulations on the same data in a concurrent manner and due to which the outcome depends on the particular order in which the access of data takes place.
To avoid race condition:
- It must be shared in a synchronized manner
- Mutual Exclusion
- Order of execution should be proper.
Critical Section Problem
- Critical section is a code segment that can be accessed by only one process at a time.
- Critical section contains shared variables which need to be synchronized to maintain consistency of data variables.
- Entry Section: It is part of the process which decides the entry of a particular process.
- Critical Section: This part allows one process to enter and modify the shared variable.
- Exit Section: Exit section allows the other process that are waiting in the Entry Section, to enter into the Critical Sections. It also checks that a process that finished its execution should be removed through this Section.
- Remainder Section: All other parts of the Code, which is not in Critical, Entry, and Exit Section, are known as the Remainder Section.
Any solution to the critical section problem must satisfy three requirements:
Mutual Exclusion : If a process is executing in its critical section, then no
other process is allowed to execute in the critical section.
Progress : If no process is executing in the critical section and other
processes are waiting outside the critical section, then only those
processes that are not executing in their remainder section can participate
in deciding which will enter in the critical section next, and the selection
can not be postponed indefinitely.
Bounded Waiting : A bound must exist on the number of times that other
processes are allowed to enter their critical sections after a process has
made a request to enter its critical section and before that request is