Job Saarnee

JOB SAARNEE

Top Most Platform for Job Updates O Level Results Answer keys AKTU MCQs

READERS WRITERS’ PROBLEM In Operating System

 READERS WRITERS’ PROBLEM In Operating
System

Table of Content

  1. Introduction to Readers-Writers problem
  2. Solution of readers-writers problem
  3. Frequently asked Question

1. Introduction to Readers-Writers problem

The
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.

Note: Reader
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.

Reader
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.

Let consider
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
inconsistency.

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
of update.  

Case 3: When
one process is writer and another process is reader then no two process is
allowed to use shared file.

Case
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

Note
Semaphore is variable which is used to execute the process in one after another
manner.

For more
details about semaphore please click here

In this
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.

Initially
value of RC is 0.

Mutex is a
binary semaphore used by reader process.

Initially
value of mutex is 1

Write_db is a
binary semaphore used by reader and writer process.

Initially
value of Write_db is 1

Procedure
for reader is

Void Reader
(Void)

 {

while (TRUE)

down (Mutex)

rc=rc+1;

if (rc==1)
down (Write_db) ;

up (Mutex);

Use the file

down (Mutex);

rc=rc-1;

if (rc==0) up
(Write_db);

up(Mutex);

process_item();

}

}  

Procedure
for writer is

Void writer
(Void)

{

while (True)

{

down
(Write_db);

use the file

up
(Write_db);

}

}  

3. Frequently asked Question

FAQ 1. Give the solution to reader/writer problem using semaphores?

FAQ 2. Give the solution of reader/writers problem by using concept of semaphore?

FAQ 3. State the readers/writers problem with readers having priority. Give solution of the problem using semaphore? 


Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

You cannot copy content of this page