3) Critical Section Problem
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
1. Process Synchronization in Operating System
A process may execute either serially or parallelly. Serial execution is when tasks are
completed one after another, while parallel execution is when multiple tasks are completed
simultaneously
Types of Processes
On the basis of synchronization, processes are categorized as one of the following two types:
Independent Process : Execution of one process does not affects the execution of other
processes.
Cooperative Process : Execution of one process affects the execution of other
processes.
Synchronization in an operating system (OS) is important because it allows multiple
processes to share resources without interfering with each other. This helps to ensure that
processes run efficiently and reliably.
Why is synchronization needed?
To prevent data inconsistency
Synchronization prevents race conditions, which occur when multiple processes try to update
the same data at the same time.
To prevent deadlocks
Synchronization helps to prevent situations where processes are unable to progress because
they are waiting for each other.
To maintain data integrity
Synchronization ensures that shared data structures are accessed in a controlled way, which
helps to maintain data integrity and consistency.
To facilitate communication
Synchronization helps to coordinate process interactions, which can improve communication
between processes.
How is synchronization achieved?
Synchronization is achieved through the use of synchronization primitives, such as
semaphores, condition variables, and mutex locks. These primitives are low-level functions
or objects that control how threads access shared resources.
Example: write race condition example(running notes)