Operating System
Module code: COM 2125
Lecturer's name: Uchechuku Desmond Anokuru
Group: 14
Date: 22/04/2026
Assignment number: 2
Names Student no Signature
Nengovhela T. 25001502
Mutavhatsindi WB. 25003806
Ndou M. 25001847
Siaga MH. 25002460
Mukwevho F. 25002317
1
PROCESS SYNCHRONISATION IN OPERATING SYSTEMS
INTRODUCTION
An operating system helps a computer manage its hardware and software. It controls important
parts of the computer, such as memory, files, devices, and running programs. In modern computers,
many programs can run at the same time. This is called multitasking.
Multitasking makes a computer more useful and efficient, but it can also cause problems. These
problems usually happen when two or more processes try to use the same resource at the same
time. For example, two processes may try to change the same file, memory location, or variable. If
this is not controlled properly, the system may give wrong results or lose data.
To prevent these problems, operating systems use process synchronisation. Process
synchronisation means controlling how processes work together when they share resources. It helps
to make sure that a shared resource is used safely and at the correct time.
This assignment explains important ideas in process synchronisation. These include the critical
section problem, synchronous and asynchronous communication, semaphores, monitors, the
bounded buffer problem, the readers-writers problem, and the dining philosophers' problem.
THE CRITICAL SECTION PROBLEM
In an operating system, different processes sometimes need to use the same resource. This
resource can be a file, memory location, variable, or device. The part of a program where a process
uses a shared resource is called the critical section.
The critical section problem happens when more than one process tries to enter its critical section at
the same time. This can cause wrong results because the processes may affect each other while
using the shared resource.
For example, if two processes are changing the same variable at the same time, they may both read
the old value before either one saves the new value. Because of this, one process may overwrite the
result of the other process. This type of problem is called a race condition.
To solve the critical section problem, three conditions must be followed. The first condition is mutual
exclusion, which means that only one process is allowed to enter the critical section at a time. The
second condition is progress, which means that if no process is inside the critical section, the system
must choose one of the waiting processes without unnecessary delay. The third condition is
bounded waiting, which means every process must get a fair chance to enter the critical section and
should not wait forever.
Operating systems use tools such as mutex locks, semaphores, monitors, and message passing to
handle this problem. These tools help processes share resources safely.
SYNCHRONOUS AND ASYNCHRONOUS COMMUNICATION
Processes may need to communicate with each other while they are running. This communication
helps them share information or coordinate their activities. Communication between processes can
be synchronous or asynchronous.
2
Synchronous communication happens when the sender and receiver must both be ready at the
same time. The sender sends a message and waits for the receiver to receive or respond to it before
continuing. A simple real-life example is a phone call because both people must be available and
active at the same time. In computer systems, synchronous communication is useful when one
process needs an immediate response from another process.
Asynchronous communication is different because the sender does not need to wait for the receiver.
The sender sends the message and continues with its work. The message can be stored in a queue,
buffer, or mailbox until the receiver is ready to process it. A common real-life example is email
because the receiver can read the message later. In computer systems, asynchronous
communication is useful because it allows processes to continue working without waiting for each
other.
SEMAPHORES
A semaphore is a synchronisation tool used by operating systems to control access to shared
resources. It is usually an integer value that helps decide whether a process can use a resource or
must wait.
Semaphores use two main operations: wait and signal. The wait operation decreases the
semaphore value. If the value shows that the resource is not available, the process must wait. The
signal operation increases the semaphore value and allows one waiting process to continue when
the resource becomes available.
There are two main types of semaphores. A binary semaphore can only have the value 0 or 1. It
works like a lock because it allows only one process to use a resource at a time. A counting
semaphore can have many values. It is used when there is more than one copy of a resource. For
example, it can control access to several printers in a system.
Semaphores are useful for solving problems such as the critical section problem and the producer-
consumer problem. However, they must be used carefully. If they are used incorrectly, they can
cause problems such as deadlock or starvation. Deadlock happens when processes wait for each
other forever. Starvation happens when a process waits for a very long time and does not get a
chance to continue.
MONITORS
A monitor is another method used for process synchronisation. It is easier to use than semaphores
because it places shared data and synchronisation rules in one structure.
A monitor allows only one process to run its procedure at a time. This means mutual exclusion is
handled automatically. Because of this, monitors can reduce programming mistakes compared to
using semaphores directly.
Monitors also use condition variables. These condition variables help processes wait until a certain
condition becomes true. If a process cannot continue, it can use a wait operation. This pauses the
process. Later, another process can use a signal operation to wake up the waiting process when the
needed condition has been met.
3
Monitors are used in many modern programming languages. Languages such as Java, C#, and
Python support monitor-like features. This makes monitors a useful and simple way to manage
shared resources.
THE BOUNDED BUFFER PROBLEM
The bounded buffer problem is also called the producer-consumer problem. It is a common example
used to explain process synchronisation.
In this problem, there are two types of processes: producers and consumers. Producers create data,
while consumers use the data. Both of them share a buffer. A buffer is a temporary storage area,
and in this problem the buffer has a fixed size.
The main problem is that the producer and consumer must use the buffer correctly. A producer must
not add data when the buffer is full because this can cause buffer overflow. A consumer must not
remove data when the buffer is empty because this can cause buffer underflow.
Synchronisation tools such as semaphores can solve this problem. A mutex can make sure that only
one process uses the buffer at a time. Other semaphores can keep track of how many spaces are
empty and how many spaces are full.
This problem is important because it appears in real systems such as data streaming, operating
systems, and programs that use multiple threads.
THE READERS-WRITERS PROBLEM
The readers-writers problem happens when many processes need to use the same shared data.
Some processes only read the data. These are called readers. Other processes change the data.
These are called writers.
Readers do not change the data, so more than one reader can read at the same time. This does not
create a problem because the data remains the same.
Writers are different because they modify the data. A writer must have exclusive access to the data
while writing. This means no reader should read while a writer is writing, and no other writer should
write at the same time.
The main challenge is fairness. If readers are always given priority, writers may wait for too long.
This is called writer starvation. If writers are always given priority, readers may also wait for too long.
A good solution must try to balance both sides.
Operating systems can solve this problem using semaphores, locks, or monitors. The readers-
writers problem is common in databases, file systems, and shared memory systems.
THE DINING PHILOSOPHERS' PROBLEM
The dining philosophers' problem is a famous example used to explain deadlock and resource
sharing.
In this problem, five philosophers sit around a table. Each philosopher can either think or eat. To eat,
each philosopher needs two forks: one fork on the left and one fork on the right. However, each fork
can only be used by one philosopher at a time.
4
The problem happens when all philosophers pick up one fork at the same time. Each philosopher
then waits for the second fork. Since everyone is waiting, no one can continue eating. This situation
is called deadlock.
This problem shows how processes can become stuck if resources are not shared properly. There
are different ways to solve it. One way is to allow only a limited number of philosophers to try eating
at the same time. Another way is to make philosophers pick up forks in a specific order. A waiter
process can also be used to control who is allowed to eat.
Semaphores and monitors can also help solve this problem. The dining philosophers' problem is
useful because it teaches important ideas about deadlock prevention and resource management.
CONCLUSION
Process synchronisation is very important in operating systems. It helps processes work together
safely when they share resources.
Without synchronisation, many problems can happen. These problems include race conditions,
deadlocks, starvation, and incorrect data.
This assignment discussed important process synchronisation concepts. These include the critical
section problem, communication methods, semaphores, monitors, the bounded buffer problem, the
readers-writers problem, and the dining philosophers' problem.
These concepts help explain how operating systems control processes that run at the same time.
They also help developers build programs that are safe, reliable, and efficient.
Understanding process synchronisation is important for computer science students and software
developers, especially when working with multi-threaded systems, operating systems, databases,
and distributed systems.
Note: This document is a simplified paraphrased version based on the provided Assignment 2 PDF.