Answer B
int rc = 0;
int c = 0;
Semaphore mutex =1;
Semaphore db =1;
void Reader(void)
{
1. L1: down (mutex):
2.
if (c ! = 0 && rc! = 0)
3. {
4. up (mutex);
5. goto L1;
6 }
7. else
8. {
9. rc = rc + 1;
10. up (mutex);
11. if (rc = = 1)
12. down (db);
13. D.B //database
14. down (mutex);
15. rc = rc - 1;
16. if (rc = = 0) up (db);
17. up (mutex);
18. }
19.}
void Writer(void)
{
while(true)
{
c = c+1;
down(db);
D.B
up(db);
c = c-1;
}
}
At line 9 process P1 increment rc by one rc=rc+1=0+1=1 then up (mutex )
suppose here P1 preempt then another process P2 come and make rc=1+1=2 here rc=2 so skip 11and 12 line and enter into CS
P2 skip 11 line so writers also enter into CS with P2
Hence break mutual exclusion