



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




An operating system is a software that manages all applications on a device and basically helps in the smooth functioning of our computer. Because of this reason, the operating system has to perform many tasks, and sometimes simultaneously. This isn't usually a problem unless these simultaneously occurring processes use a common resource. Inconsistency of data can occur when various processes share a common resource in a system which is why there is a need for process synchronization in the operating system.
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 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. Producer-Consumer problem is a classical synchronization problem in the operating system. With the presence of more than one process and limited resources in the system the synchronization problem arises. If one resource is shared between more than one process at the same time then it can lead to data inconsistency. What is Producer Consumer Problem? Before knowing what Producer-Consumer Problem is we have to know what are Producer and Consumer. In operating System Producer is a process which is able to produce data/item. Consumer is a Process that is able to consume the data/item produced by the Producer. Both Producer and Consumer share a common memory buffer. This buffer is a space of a certain size in the memory of the system which is
used for storage. The producer produces the data into the buffer and the consumer consumes the data from the buffer. So, what are the Producer-Consumer Problems?
A boolean Flag[]: A boolean array Flag represents which process is which process wants to enter into the critical solution. int Turn: A integer variable Turn indicates the process number which is ready to enter into the critical section. Let us look at some disadvantages of Peterson's solution are: The Peterson's solution involves Busy waiting. The solution is also limited to only 2 processes.
This is a two-process solution. Let us consider two cooperative processes P and P2. The entry section and exit section are shown below. Initially, the value of interested variables and turn variable is 0. Initially process P1 arrives and wants to enter into the critical section. It sets its interested variable to True (instruction line 3) and also sets turn to 1 (line number 4). Since the condition given in line number 5 is completely satisfied by P1 therefore it will enter in the critical section.
The Bakery algorithm is one of the simplest known solutions to the mutual exclusion problem for the general case of N process. Bakery Algorithm is a critical section solution for N processes. The algorithm preserves the first come first serve property. Before entering its critical section, the process receives a number. Holder of the smallest number enters the critical section. If processes Pi and Pj receive the same number
A semaphore is a signaling mechanism, and a process can signal a process that is waiting on a semaphore. This differs from a mutex in that the mutex can only be notified by the process that sets the shared lock. Semaphores make use of the wait() and signal() functions (two atomic operations) for synchronization among the processes. There are two kinds of semaphores: