0
1.2kviews
Process Synchronization in MOS
1 Answer
2
17views

On the basis of synchronization, processes are categorized as one of the following two types:

Independent Process: The process which is executed independently and doesn’t affect the execution of other process is called an independent process.

Cooperative Process: Execution of one process affects the execution of other processes is called cooperative processes. Result of one process depends on another process.

Process Synchronization occurs when there are multiple processes for execution and all are shares a system resources (like memory location, I/O devices, data structure…etc.) and it ensures the coordination between processes that use shared data values. It happens in an operating system between cooperating processes.

Cooperating processes are processes that share the same resources by keeping a mutual understanding between them. While executing many concurrent processes, process synchronization helps to maintain shared data consistency and cooperating process execution.

Processes have to be scheduled to ensure that concurrent access to shared data does not create inconsistencies. Data inconsistency can result in what is called a race condition.

A race condition occurs when two or more operations are executed at the same time, not scheduled in the proper sequence, and not exited in the critical section correctly.

Critical Section Problem

There are a number of processes active in a group but only one process can access the critical section at a given point of time while others have to wait. In this phase, other processes are not allowed to access the shared data resources. For example, if one process is changing the variable, updating the table or writing the files at the same time other processes will be waiting for the operation. Each process must ask the permission to enter into the critical section.

do{
    entry part //Control the entry into critical section & locks the required resources
    critical section
    exit  part // removes the lock from resources and other knows that critical section is over
    remainder section//rest of the section
} while TRUE;

Entry part

In this section, the process enters into critical section out of several processes.

Exit Section

This process allows the other process that is waiting in the Entry Section, to enter into the Critical Sections. It checks that a process that after a process has finished execution in Critical Section can be removed through this Exit Section.

Remainder Section

The other parts of the Code other than Entry Section, Critical Section, and Exit Section are known as Remainder Section.

Example :

shared var int l = 0; // lock (l) is not set initially
int v = 1; 
while ( v == 1) do  each (v, lock); //entry section
//critical section (within this, l = 1) 
l = 0; // exit section
other code, not mutually exclusive     // lock is released

This is the so-called spinlock because the process processes on the lock variable until the lock is released.

Solutions to critical section problem

  1. Mutual Exclusion

    It states that no other process is allowed to execute in the critical section if a process is executing in the critical section. e.g. If process p0 is updating the data of the table, then p1 will not be allowed to enter the critical section.

  2. Progress

    When no process is in the critical section, then any process from outside that request for execution can enter in the critical section without any delay. Only those processes can enter that have requested and have a finite time to enter the process.

  3. Bounded Waiting

    A bound must exist on the number of times that other processes are allowed to enter their critical section after a process has made a request to enter its critical section and before that request is granted. There is a limit on a process that how many processes will actually enter into a critical section after request and before the request is granted.

Please log in to add an answer.