READERS WRITERS’ PROBLEM In Operating
Table of Content
- Introduction to Readers-Writers problem
- Solution of readers-writers problem
- Frequently asked Question
1. Introduction to Readers-Writers problem
readers-writers problem is a most popular problem of synchronization between
process, it is relating to file that is shared between more than one process
(reader process or writer process) at a time.
and Writer are two process that are needed to synchronize otherwise it can lead
to the following problem.
- Inconsistency means wrong value
- Dirty read
- Loss of update
Out of set
containing more than one process, some of the processes are reader process and
some of them are writer process.
process is interested in reading the file or data but not going to write
anything on file or data. Writer process is interested in reading and writing both.
Note: In short,
we are trying to provide synchronization between Reader and Writer Process in
order to access common database/file/data.
all case in this scenario
Case 1: when
one process is reader and another process is Writer then no two process is
allowed to use shared file. In this reader is reading dirty value means
Case 2: when
one process is writer and another process is Writer then no two process is
allowed to use shared file. In the both process trying update the file mean lot
Case 3: When
one process is writer and another process is reader then no two process is
allowed to use shared file.
4: when one process is reader and another process is reader then there is no
problem in sharing the variable. There is no problem in this case as both are
reading the data, there is no change in value of data or file.
In order to
maintain this scenario and get ride form inconsistency, the solution for reader
writer problem is semaphore.
2. Solution of readers-writers problem
Semaphore is variable which is used to execute the process in one after another
details about semaphore please click here
solution we are going to make use of two semaphore and one variable
There are two
procedure to achieve
RC is a
reader count represents the number of reader use file at any point of time.
value of RC is 0.
Mutex is a
binary semaphore used by reader process.
value of mutex is 1
Write_db is a
binary semaphore used by reader and writer process.
value of Write_db is 1
for reader is
down (Write_db) ;
Use the file
if (rc==0) up
for writer is
use the file