Process synchronization
Process synchronization
A) A critical section is a part of a program where shared resources like memory or files are
accessed by multiple processes or threads. To avoid issues like data inconsistency or race
conditions, synchronization techniques ensure that only one process or thread uses the critical
section at a time.
A diagram that demonstrates the critical section is as follows −
In the above diagram, the entry section handles the entry into the critical section. It
acquires the resources needed for execution by the process.
The exit section handles the exit from the critical section. It releases the resources and also
informs the other processes that the critical section is free.
Solution to the Critical Section Problem
The critical section problem needs a solution to synchronize the different processes. The
solution to the critical section problem must satisfy the following conditions −
Mutual Exclusion
Mutual exclusion implies that only one process can be inside the critical section at any time.
If any other processes require the critical section, they must wait until it is free.
Progress
Progress means that if a process is not using the critical section, then it should not stop any
other process from accessing it. In other words, any process can enter a critical section if it is
free.
Bounded Waiting
Bounded waiting means that each process must have a limited waiting time. Itt should not
wait endlessly to access the critical section.
No Assumption
No assumption regarding hardware software and speed that is what ever mechanisms we are
designing that must me work properly in any hardware and software of a computer
2. Producer Consumer Problem in OS
A) Producer-Consumer problem is a classical synchronization problem in the operating
system.
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
Example: Running notes example with diagram explanation of 2 cases best and worst
(write here)
Solutions
Synchronization techniques: Ensure that the shared resource is used safely and
orderly
Semaphores: A synchronization tool that manages access to shared resources
Mutex locks: Ensure that only one thread accesses the data structure describing the
buffer at a time