Jenkins
15 Best Jenkins Alternatives in 2021
Jenkins is an open source Continuous Integration platform and is a cruial tool in DevOps...
Process Synchronization is the task of coordinating the execution of processes in a way that no two processes can have access to the same shared data and resources.
It is specially 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 data at the same time.
This can lead to the inconsistency of shared data. So the change made by one process not necessarily reflected when other processes accessed the same shared data. To avoid this type of inconsistency of data, the processes need to be synchronized with each other.
In this operating system tutorial, you will learn:
For Example, process A changing the data in a memory location while another process B is trying to read the data from the same memory location. There is a high probability that data read by the second process will be erroneous.
Here, are four essential elements of the critical section:
A critical section is a segment of code which can be accessed by a signal process at a specific point of time. The section consists of shared data resources that required to be accessed by other processes.
In the critical section, only a single process can be executed. Other processes, waiting to execute their critical section, need to wait until the current process completes its execution.
The critical section need to must enforce all three rules:
In Process Synchronization, critical section plays the main role so that the problem must be solved.
Here are some widely used methods to solve the critical section problem.
Peterson's solution is widely used solution to critical section problems. This algorithm was developed by a computer scientist Peterson that's why it is named as a Peterson's solution.
In this solution, when a process is executing in a critical state, then the other process only executes the rest of the code, and the opposite can happen. This method also helps to make sure that only a single process runs in the critical section at a specific time.
Example
PROCESS Pi
FLAG[i] = true
while( (turn != i) AND (CS is !free) ){ wait;
}
CRITICAL SECTION FLAG[i] = false
turn = j; //choose another process to go to CS
Some times the problems of the Critical Section are also resolved by hardware. Some operating system offers a lock functionality where a Process acquires a lock when entering the Critical section and releases the lock after leaving it.
So when another process is trying to enter the critical section, it will not be able to enter as it is locked. It can only do so if it is free by acquiring the lock itself.
Synchronization hardware not simple method to implement for everyone, so strict software method known as Mutex Locks was also introduced.
In this approach, in the entry section of code, a LOCK is obtained over the critical resources used inside the critical section. In the exit section that lock is released.
Semaphore is simply a variable that is non-negative and shared between threads. It is another algorithm or solution to the critical section problem. It is a signaling mechanism and a thread that is waiting on a semaphore, which can be signaled by another thread.
It uses two atomic operations, 1)wait, and 2) signal for the process synchronization.
WAIT ( S ): while ( S <= 0 ); S = S - 1; SIGNAL ( S ): S = S + 1;
Jenkins is an open source Continuous Integration platform and is a cruial tool in DevOps...
What is CISC? CISC was developed to make compiler development easier and simpler. The full form of...
Following are frequently asked questions in interviews for freshers as well as experienced Java...
Ansible is a DevOps tool which automates software provisioning, configuration management, and...
What is the Knapsack Problem? Knapsack Problem algorithm is a very helpful problem in...
The most frequent tasks that you perform on your PC is creating, moving or deleting Files. Let's...