edited by
1,192 views
4 votes
4 votes

Consider the following code used by the classical readers and writers.

Note: rc = rc+1; will execute in 3 instructions like load, increment and then store.
Which of the below statement is true, regarding synchronizing the classical readers and writers?

  • The above solution is correct, and it is properly synchronizing the readers and writers.
  • Both reader and writers will enter into data base at the same time.
  • It is possible for deadlock.
  • Both (b) and (c) are true.

I think it should be a but answet is d can somebody provide the simulation 

edited by

1 Answer

Best answer
11 votes
11 votes

yes, option d is correctas both b and c are true.

rc=rc+1 executes in three instructions so

Case(1) readers and writers at the same time in database:

 suppose there are two reader R1 and R2 and writer W1

W1 excutes Down (db) and makes db =0 goes in/uses Database

now R1 executes Rc=Rc+1 update Rc=1 and preempts

then R2 executes Rc=Rc+1 and down mutex changing mutex=0 and condition if(Rc==1) is false so Reader R2 goes into Database and W1 already in Database.

Case2: for deadlock

suppose there are two reader R1 and R2 and writer W1. R1 already in Database by making Mutex=1 db=0 and Rc=1. if writer W1 tries to write will suspend on down(db).

and now reader R2 tries to read the database and R1 tries to come out of database as follows

R2 updates Rc=2 then R1 tries to come out of database by updating Rc=Rc-1=2-1=> Rc=1 makes condition if(rc==0) false and makes mutex=1 and db unchanged and rc=1.

now R2 excutes down (mutex) mutex=0 succesfully and then checks the condition if (rc==1) which is true so executes down (db) and suspend on db. now another readers will be suspended on mutex and writers will be at db.and deadlock occurs.
i think its correct. but may go wrong. verify it.

selected by

Related questions

0 votes
0 votes
0 answers
1
Hopealways asked Dec 1, 2018
445 views
In these type of questions “Will we NOT consider CONTEXT SWITCHING unless mentioned???”If context switching is ALLOWED, minimum value will be 8...Correct me if I’m ...