0% found this document useful (0 votes)
310 views

Readers Writers Problem in Os

The Readers Writers problem involves coordinating threads that perform read and write operations on shared resources like files. It aims to allow multiple reader threads but only one writer thread at a time to prevent inconsistencies. Semaphores are often used to implement mutual exclusion and ensure only one thread can access the resource at a time. Solutions include prioritizing either readers or writers. Starvation is prevented through techniques like queueing and fairness policies.

Uploaded by

harmandeep kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
310 views

Readers Writers Problem in Os

The Readers Writers problem involves coordinating threads that perform read and write operations on shared resources like files. It aims to allow multiple reader threads but only one writer thread at a time to prevent inconsistencies. Semaphores are often used to implement mutual exclusion and ensure only one thread can access the resource at a time. Solutions include prioritizing either readers or writers. Starvation is prevented through techniques like queueing and fairness policies.

Uploaded by

harmandeep kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

READERS WRITERS

PROBLEM in OS
The Readers Writers problem is a classic synchronization
problem in operating systems. It involves coordinating
multiple threads that perform read and write operations
on a shared resource, such as a file or a library.

\
by Mohammed Ajmal Fayiz
Problem Description

The problem arises when multiple threads try to access the shared resource
simultaneously. If a thread is reading from the resource, other threads can also
read from it simultaneously. However, if a thread is writing to the resource, no
other thread can read from or write to it. This can lead to issues with data
consistency and efficiency.
Solution Using Semaphores

A common solution to the Readers Writers problem is to


use semaphores. Semaphores are synchronization
primitives that can control access to a shared resource.
Using semaphores, we can implement mutual exclusion
to ensure that only one thread can access the resource at
a time.
Reader-Priority Solution

In the Reader-Priority solution, we prioritize readers


over writers. This means that if a reader is currently
accessing the resource, other readers can also access it
simultaneously. Writers, on the other hand, have to
wait until there are no readers or writers accessing the
resource before they can write to it.
Writer-Priority Solution

In the Writer-Priority solution, we prioritize writers


over readers. This means that whenever a writer wants
to access the resource, it can do so immediately, even
if there are other readers currently accessing it.
Readers, however, have to wait until there are no
writers accessing the resource before they can read
from it.
Starvation and its Prevention

Starvation can occur in the Readers Writers


problem when a thread is consistently denied
access to the shared resource, resulting in it being
unable to perform its task. To prevent starvation,
we can use techniques such as queueing and
implementing fairness policies to ensure that all
threads eventually get access to the resource.
Fairness of Solutions

The fairness of the Readers Writers solutions refers to how well they distribute
access to the resource among the threads. A fair solution ensures that no thread
is consistently denied access for an extended period. Various fairness metrics
and strategies can be employed to achieve fairness in the context of the
Readers Writers problem.
Conclusion
The Readers Writers problem is a fundamental synchronization problem in
operating systems. While various solutions exist, there is ongoing research to
optimize the performance and scalability of these solutions. Future work may
focus on adaptability to different systems and enhancing the fairness of the
solutions.

You might also like