Process Synchronization in Operating System (2024)

In this tutorial, we will be covering the concept of Process synchronization in an Operating System.

Process Synchronization was introduced to handle problems that arose while multiple process executions.

Process is categorized into two types on the basis of synchronization and these are given below:

  • Independent Process

  • Cooperative Process

Independent Processes

Two processes are said to be independent if the execution of one process does not affect the execution of another process.

Cooperative Processes

Two processes are said to be cooperative if the execution of one process affects the execution of another process. These processes need to be synchronized so that the order of execution can be guaranteed.

Process Synchronization

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.

Race Condition

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.

Mainly this condition is a situation that may occur inside the critical section. Race condition in the critical section happens when the result of multiple thread execution differs according to the order in which the threads execute. But this condition is critical sections can be avoided if the critical section is treated as an atomic instruction. Proper thread synchronization using locks or atomic variables can also prevent race conditions.

Critical Section Problem

A Critical Section is a code segment that accesses shared variables and has to be executed as an atomic action. It means that in a group of cooperating processes, at a given point of time, only one process must be executing its critical section. If any other process also wants to execute its critical section, it must wait until the first one finishes. The entry to the critical section is mainly handled by wait() function while the exit from the critical section is controlled by the signal() function.

Process Synchronization in Operating System (1)

Entry Section

In this section mainly the process requests for its entry in the critical section.

Exit Section

This section is followed by the critical section.

The solution to the Critical Section Problem

A solution to the critical section problem must satisfy the following three conditions:

1. Mutual Exclusion

Out of a group of cooperating processes, only one process can be in its critical section at a given point of time.

2. Progress

If no process is in its critical section, and if one or more threads want to execute their critical section then any one of these threads must be allowed to get into its critical section.

3. Bounded Waiting

After a process makes a request for getting into its critical section, there is a limit for how many other processes can get into their critical section, before this process's request is granted. So after the limit is reached, the system must grant the process permission to get into its critical section.

Solutions for the Critical Section

The critical section plays an important role in Process Synchronization so that the problem must be solved.

Some widely used method to solve the critical section problem are as follows:

1.Peterson's Solution

This is widely used and software-based solution to critical section problems. Peterson's solution was developed by a computer scientist Peterson that's why it is named so.

With the help of this solution whenever a process is executing in any critical state, then the other process only executes the rest of the code, and vice-versa can happen. This method also helps to make sure of the thing that only a single process can run in the critical section at a specific time.

This solution preserves all three conditions:

  • Mutual Exclusion is comforted as at any time only one process can access the critical section.

  • Progress is also comforted, as a process that is outside the critical section is unable to block other processes from entering into the critical section.

  • Bounded Waiting is assured as every process gets a fair chance to enter the Critical section.

Process Synchronization in Operating System (2)

The above shows the structure of process Pi in Peterson's solution.

  • Suppose there are N processes (P1, P2, ... PN) and as at some point of time every process requires to enter in the Critical Section

  • A FLAG[] array of size N is maintained here which is by default false. Whenever a process requires to enter in the critical section, it has to set its flag as true. Example: If Pi wants to enter it will set FLAG[i]=TRUE.

  • Another variable is called TURN and is used to indicate the process number that is currently waiting to enter into the critical section.

  • The process that enters into the critical section while exiting would change the TURN to another number from the list of processes that are ready.

  • Example: If the turn is 3 then P3 enters the Critical section and while exiting turn=4 and therefore P4 breaks out of the wait loop.

Synchronization Hardware

Many systems provide hardware support for critical section code. The critical section problem could be solved easily in a single-processor environment if we could disallow interrupts to occur while a shared variable or resource is being modified.

In this manner, we could be sure that the current sequence of instructions would be allowed to execute in order without pre-emption. Unfortunately, this solution is not feasible in a multiprocessor environment.

Disabling interrupt on a multiprocessor environment can be time-consuming as the message is passed to all the processors.

This message transmission lag delays the entry of threads into the critical section, and the system efficiency decreases.

Mutex Locks

As the synchronization hardware solution is not easy to implement for everyone, a strict software approach called Mutex Locks was introduced. In this approach, in the entry section of code, a LOCK is acquired over the critical resources modified and used inside the critical section, and in the exit section that LOCK is released.

As the resource is locked while a process executes its critical section hence no other process can access it.

  • ← Prev
  • Next →
Process Synchronization in Operating System (2024)

FAQs

Process Synchronization in Operating System? ›

Processes Synchronization or Synchronization is the way by which processes that share the same memory space are managed in an operating system. It helps maintain the consistency of data by using variables or hardware so that only one process can make changes to the shared memory at a time.

What is process synchronization in OS with example? ›

Process synchronization in OS is the task of coordinating the execution of processes in such a way that no two processes can access the same shared data and resources. It is a critical part of operating system design, as it ensures that processes can safely share resources without interfering with each other.

Which is a synchronization tool in OS? ›

Explanation: Semaphore is a synchronization tool. Semaphore is a mechanism which synchronizes or controls access of threads on critical resources.

What is process synchronisation in RTOS? ›

When two or more process cooperates with each other, their order of execution must be preserved otherwise there can be conflicts in their execution and inappropriate outputs can be produced.

What is synchronization explain in detail? ›

Synchronization of movement is defined as similar movements between two or more people who are temporally aligned. This is different from mimicry, which occurs after a short delay. Line dance and military step are examples. Muscular bonding is the idea that moving in time evokes particular emotions.

What is a real life example of process synchronization? ›

It is necessary that processes are synchronized with each other as it helps avoid the inconsistency of shared data. For example: A process P1 tries changing data in a particular memory location. At the same time another process P2 tries reading data from the same memory location.

What is a real time example of synchronization? ›

Synchronization in java. i.e In multi threading is used to lock the resource it maybe Bank account or printer or any resource . Real Time example withdrawal of money from bank account .

What is synchronization problem in OS? ›

Synchronization Problems

Picture a scenario where multiple processes are either putting data into the buffer (producers) or taking data out (consumers). The crux is to ensure that a producer doesn't add data to a full buffer, & a consumer doesn't try to remove data from an empty one.

What are the two types of Synchronisation? ›

There are two types of process synchronization: synchronous or periodic, also called Time-triggered (where a clock transition is the trigger to move information across a communications network) and asynchronous or aperiodic also called Event-triggered, (where specific Event signals act as the triggers to change State).

What is synchronization in Windows? ›

File synchronization makes you more productive

You can sync the files in your OneDrive or site libraries so they're always available on your computer, even if you're offline. Once they're synced, you can add, edit, or remove files from your computer, and your changes sync automatically.

Which Cannot be used for process synchronisation? ›

Final answer: Several constructs such as semaphores, mutex locks, monitors and condition variables can be used for process synchronization. However, the goto statement cannot be used for this purpose because it is a control flow construct that has no mechanism for resource control or inter-process coordination.

Why do we use semaphore in OS? ›

The main aim of using a semaphore is process synchronization and access control for a common resource in a concurrent environment. The initial value of a semaphore depends on the problem at hand. Usually, we use the number of resources available as the initial value.

Why do we need process synchronization? ›

The need for synchronization originates when processes need to execute concurrently. The main purpose of synchronization is the sharing of resources without interference using mutual exclusion. The other purpose is the coordination of the process interactions in an operating system.

What is the application of process synchronization? ›

Process synchronization needs to be implemented to prevent data inconsistency among processes, process deadlocks, and prevent race conditions, which are 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.

What are the 4 types of deadlock in OS? ›

A deadlock in OS is a situation in which more than one process is blocked because it is holding a resource and also requires some resource that is acquired by some other process. The four necessary conditions for a deadlock situation are mutual exclusion, no preemption, hold and wait and circular set.

Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 5810

Rating: 4.7 / 5 (57 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.