Process
Synchronisation and
Communication in
Operating Systems
Process synchronization is a fundamental concept in operating
systems, ensuring that multiple concurrent processes can access
shared resources without conflicts or data corruption. It involves
techniques like mutual exclusion, semaphores, and inter-process
communication (IPC) to coordinate the execution of tasks and
maintain the integrity of the system. This presentation will provide a
comprehensive overview of these essential principles, equipping you
with the knowledge to design and implement effective
synchronization mechanisms in your software applications.
by 49 . Sumit Belure
Mutual Exclusion and Critical Sections
Mutual Exclusion Critical Sections Synchronization Challenges
Mutual exclusion is a technique that Critical sections are the parts of a Implementing mutual exclusion and
ensures only one process can program where the shared resource managing critical sections can be
access a shared resource at a time. is accessed. These sections must be challenging, as it requires careful
This is achieved by defining critical protected to ensure that only one coordination between multiple
sections, which are blocks of code process can execute them at a time. concurrent processes. Factors such
where the shared resource is Proper management of critical as starvation, deadlocks, and race
accessed. Only one process can sections is crucial for avoiding data conditions must be addressed to
enter the critical section at a time, corruption and maintaining the ensure the correct and efficient
preventing race conditions and overall integrity of the system. execution of the system.
ensuring data consistency.
Semaphores and Their
Implementation
Semaphore Concept
1
Semaphores are a synchronization mechanism used
to control access to shared resources. They act as a
counter, keeping track of the number of available
resources. Processes can acquire (wait) or release
(signal) the semaphore, allowing for controlled access
to the shared resource.
Semaphore Operations
2
The two main operations on a semaphore are wait()
and signal(). The wait() operation decrements the
semaphore value, and if the value becomes negative,
the process is blocked and added to a queue. The
signal() operation increments the semaphore value,
and if there are any blocked processes, one of them
is unblocked and allowed to proceed.
Semaphore Implementation
3
Semaphores can be implemented using a variety of
techniques, such as using a counter variable and a
queue of blocked processes. The specific
implementation details may vary depending on the
operating system and the underlying hardware
architecture.
The Producer-Consumer
Problem
The Problem Synchronization
Mechanisms
The producer-consumer
problem is a classic To solve the producer-
synchronization problem in consumer problem,
which a producer process synchronization
generates data items and mechanisms such as
places them into a shared semaphores, condition
buffer, while a consumer variables, and monitors are
process removes these used. These mechanisms
items from the buffer for ensure that the producer
processing. The challenge is and consumer processes are
to ensure that the producer properly coordinated,
does not add items to a full avoiding race conditions and
buffer and that the maintaining the integrity of
consumer does not remove the shared buffer.
items from an empty buffer.
Real-World Applications Variations and
Complexities
The producer-consumer
problem has numerous real- The producer-consumer
world applications, including problem can be further
message queues, buffer extended and modified to
management in network address more complex
protocols, and resource scenarios, such as multiple
management in operating producers, multiple
systems. Understanding and consumers, bounded or
effectively implementing unbounded buffers, and
solutions to this problem is priority-based processing.
crucial for building robust These variations introduce
and efficient software additional challenges that
systems. require more sophisticated
synchronization techniques.
The Dining Philosophers
Problem
The Problem
The dining philosophers problem is a classic
synchronization problem that illustrates the challenge
1 of avoiding deadlocks and starvation in concurrent
systems. In this problem, a group of philosophers sit
around a table, each with a plate of food and a fork,
and they must acquire two forks to eat.
Deadlock Avoidance
The key to solving the dining philosophers problem is
to avoid deadlocks, where each philosopher is holding
one fork and waiting for the other, resulting in a
2
circular wait. This can be achieved through strategies
like resource ordering, timeout-based acquisition, or
the introduction of a coordinator process to manage
the forks.
Starvation Prevention
In addition to deadlock avoidance, the solution must
also address the issue of starvation, where a
philosopher may be continuously denied the
opportunity to eat due to the actions of other
3
philosophers. Techniques like fair scheduling, priority-
based acquisition, or the use of a central coordinator
can help prevent starvation and ensure that all
philosophers have a fair chance to access the shared
resources.
Deadlocks and Starvation
1 Deadlocks 2 Starvation
Deadlocks occur when Starvation is a situation
two or more processes where a process is
are waiting for each other continuously denied
to release resources, access to a shared
resulting in a circular wait resource, even though the
that prevents any resource is available. This
progress from being can happen due to the
made. Deadlocks can lead unfair scheduling of
to system failures and processes or the
must be carefully avoided prioritization of other
in concurrent systems. processes. Starvation can
lead to unresponsive
systems and must be
addressed through proper
resource management
and scheduling
algorithms.
3 Detection and Avoidance
Techniques for detecting and avoiding deadlocks and
starvation include resource ordering, resource allocation
graphs, banker's algorithm, and the use of priority-based
scheduling. These methods help identify and prevent potential
deadlock and starvation scenarios, ensuring the smooth and
efficient operation of the system.
Inter-Process Communication
(IPC)
Message Queues Shared Memory
Message queues allow processes Shared memory allows multiple
to exchange data by sending and processes to access a common
receiving messages. They region of memory, enabling them
provide a way for processes to to share data directly. This
communicate asynchronously, method of IPC is efficient but
where the sender and receiver requires careful synchronization
do not need to be active at the to prevent race conditions and
same time. data corruption.
Sockets Pipes
Sockets provide a way for Pipes are a simple form of IPC
processes to communicate over that allow one process to write
a network, allowing them to data to a channel, which can
exchange data and coordinate then be read by another process.
their actions. Sockets can be Pipes are commonly used for
used for both local and remote passing data between related
communication, enabling processes, such as in a shell
distributed systems and client- pipeline.
server architectures.
Conclusion and Key Takeaways
1 Mutual Exclusion and 2 Semaphores and
Critical Sections Synchronization
Mechanisms
Ensuring that only one
process can access a Semaphores and other
shared resource at a time synchronization
is crucial for maintaining primitives, such as
data integrity and condition variables and
preventing race monitors, provide
conditions. powerful tools for
coordinating the
execution of concurrent
processes.
3 Deadlock and 4 Inter-Process
Starvation Avoidance Communication (IPC)
Understanding and Effective communication
addressing the risks of between processes, using
deadlocks and starvation techniques like message
is essential for building queues, shared memory,
robust and reliable and sockets, is crucial for
concurrent systems. building complex,
distributed systems.
Key Takeaways
Mastering Avoiding Deadlocks and
Synchronization Starvation
Understanding and Proactively identifying and
implementing effective addressing the risks of
synchronization deadlocks and starvation is
mechanisms, such as crucial for maintaining the
mutual exclusion and overall stability and
semaphores, is essential for responsiveness of the
building reliable and system.
efficient concurrent
systems.
Effective Inter-Process Communication
Leveraging various IPC techniques, like message queues, shared
memory, and sockets, allows for efficient data exchange and
coordination between concurrent processes, enabling the
development of complex, distributed applications.