Table of Contents
ToggleWhat is Process Synchronization in OS?
Process Synchronization can be done on hardware as well software level. Process Synchronization is the job of managing the execution of processes in such a manner that ensures that no two processes be able to access the same data and resources.
It is especially important in multi-process systems in which multiple processes are running together or when more than one process is trying to access the same resource or data simultaneously.
The problem of process synchronization is encountered when a concurrent processes try to access shared resources. There are various ways that process synchronization can be done on which are further discussed within this article.
Process synchronization can be done on _____
(a) hardware level
(b) software level
(c) both hardware and software leve
(d) none of the mentioned
Right option is (c) both hardware and software level
Explanation: Process synchronization can be done on both hardware and software level. Critical section problems can be resolved using hardware synchronisation. But this method is not simple to implement hardware synchronization so software synchronization is mostly used.
Why Process Synchronization Is Needed?
Let us take a look at why exactly we need Process Synchronization. For example, If a process A is trying to read the data present in a memory location while another process B is trying to change the data present at the same location, there is a high chance that the data read by the process A will be incorrect.
Race Condition
When more than one program is either running the same program or connecting to the exact memory, or any shared variable. this situation, there is an possibility there is a chance that my output, or amount of the shared variable are not correct, and for that reason each process is running the race to determine if my output is right. This is referred to as race conditions. Since multiple processes process and access the operations on the identical data in a simultaneous manner , results depend on the time in which the access to the data occurs.
Most commonly, this is an issue that can occur within the critical section. Race conditions inside the critical part occurs when the results of multiple threads’ execution is different depending on the sequence in which threads are executed. However, this is a condition that affects crucial sections can be prevented when the critical section is treated as an atomic command. A proper thread synchronization process using lock or even atomic variables could help to prevent race conditions.
What is Critical Section Problem?
Critical sections are section of code that can be accessed via signals at a certain point in time. The section comprises shared data resources which need to be used through other process.
- The entry into this critical area is managed through waiting() function and is shown in the form P().
- The exit of the critical section will be controlled via the signal() function, which is represented in the form the symbol V().
Within the crucial section only one process can be run. Others processes, which are waiting to complete their critical section, have be patient until currently running process has completed its execution.
To know more about critical section refer this article.
Process synchronization can be done on both hardware and software level. Let’s first how process synchronization can be done on at each level in detail.
Process synchronization can be done on hardware level by
- Synchronization Hardware: Sometimes, the issues of problems with the Critical Section are also resolved with the help of hardware. Certain operating systems offer locks, where a Process is able to acquire a lock upon entering the Critical section , and removes the lock when having left it. If another process attempts to access the critical area that is locked, it won’t be able to do so because the lock is closed. It will only be able to do this when it is unlocked by purchasing the lock.
- Mutex Locks: Synchronization hardware isn’t an easy process to use for all So a strict software approach called Mutex Locks was also introduced. In this way during the entry portion of the code, a LOCK is created over the crucial resources utilized in that critical area. In the exit, the lock is let go.
Process synchronization can be done on software level by
- Semaphore Solution: Semaphore is just a number that is not negative and is shared among threads. It is a different technique that solves the crucial section issue. It’s a signaling mechanism and a thread waiting for a semaphore which is able to be signaled by a different thread.
Conclusion
In this article we discussed about two different ways where process synchronization can be done on and we discussed various ways how process synchronization can be done on at hardware and software level. Checkout more about deadlock and related articles here
Got a question or just want to chat? Comment below or drop by our forums, where a bunch of the friendliest people you’ll ever run into will be happy to help you out!