in Operating System edited by
1,376 views
2 votes
2 votes

 

in Operating System edited by
by
1.4k views

3 Comments

I got C as the answer but correct answer is B.
0
0
Little help here :/
0
0

the only problem in c option that if one process got preempted on A:Down(S) then other can not come and will be clocked on m. but in question it is mentioned that at present 100 readers can read the book simultaneously.

So answer will be B. 

0
0

4 Answers

2 votes
2 votes
In the line 8 of while loop,  rc-- should be the correct implementation.

Considering that, the first reader downs the database and last reader ups the database. Each reader increases the readers count and wait for S. Mutex m is a mutex lock on accessing variable rc. It is placed around rc statements. down(s) before read and up(s) after read operations are done.

So A:up(m),B;down(s),C:up(m),D:up(s)

Also,I think db should not be a mutex, it should be a binary semaphore,since mutex has ownership,i.e the reader which downs the database will only be able to up the database,which is not the case here.
edited by
1 vote
1 vote

the difference between B and C is Deadlock.

option C cause deadlock how? let’s see suppose there are already 100 readers in DBMS so s = 0 means no more readers are allowed to go … now 101 reader comes in and acquire mutex but got trapped in wait(s) before releasing mutex. now no reader in DBMS can go and acquire mutex to free database for any other reader or writer.

option B avoids this situation hence it is a correct option

0 votes
0 votes
There is typo in question

Answer should be B

A= up(m) to providing entry for others readers in CS

B= down(s) because s value reduces by one after entering one reader in CS

C=up(m) to give a chance to other readers to come out from CS

D=up(s)  means to increasing the no of readers come out from CS
0 votes
0 votes
This is classic reader writers problem as its mentioned, with just one modification as here a maximum of 100 readers are allowed.

To make access to rc variable mutually exclusive we have Down(m) and UP(m). Only option B satisfies this.

Between B and C we are performing the read operations, here we have to ensure that a maximum of 100 readers are allowed at a time. So B will be Down(s). (Remember S=100 initially, so it indicated how many more readers can get in.

C will be UP(s) as we have to make rc decrement mutually exclusive,

D is UP(s) as now reader is out, so we can say 1 more reader can come by incrementing s.

So B is correct.

Related questions