Deprecated: Implicit conversion from float-string "1674212826.184" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1674212826.184" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1674212826.184" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1674212826.184" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1674212826.184" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1580078725.276" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1580078725.276" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1580078725.276" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1580078725.276" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1580078725.276" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1604246116.297" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1604246116.297" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1604246116.297" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1604246116.297" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1604246116.297" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594

Deprecated: Implicit conversion from float-string "1640237993.840" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1640237993.840" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1640237993.840" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1640237993.840" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1640237993.840" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 594
Operating System: synchronization reader's writer's problem.
edited by
2,303 views
1 votes
1 votes
int readers_count = 0;
semaphore mutex = 1; // binary semaphore
semaphore db = 1;    // binary semaphore

void reader() {
  while(TRUE) {
 x. down(mutex);    //or  wait(mutex) or P(mutex)
    readers_count = readers_count + 1;
 y. if(readers_count == 1) down(db);
    up(mutex);       // or signal(mutex) or // V(mutex)

    < access DB >
    
    down(mutex);
    readers_count = readers_count - 1;
 p. if(readers_count == 0) up(db);
 q. up(mutex);       //or signal(mutex) or // V(mutex)
  }
}

void writer() {
  while(TRUE) {
 z: down(db);

    < access DB >
    
    up(db);
  }
}

What happens when positions of lines p and q are interchanged ?

  • a. No problem, the solution works fine.
  • b. Multiple readers and writers are allowed in the database at the same time.
  • c. There is possibility of deadlock.
  • d. None of the above.
edited by

2 Answers

0 votes
0 votes
p. if(readers_count == 0) up(db);
 q. up(mutex);  
 1. Before it, we donot have writer. We bring mutex up in code. Take an example. Say rc=0 ; Last reader say R3 is 
leaving it makes rc=0. Now still db is not allowed. We have up mutuex. So a reader r1 enters and down mutex check 
rc ==1 then tries to down db but it cannot and deadlock occurs.

 

0 votes
0 votes

the point of attention was there is violation of mutual exclusive excess of reader_count in end part of reader’s process code which will cause the deadlock in system but how? try yourself !

edited by

Related questions


Deprecated: Implicit conversion from float-string "1542355159.371" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1542355159.371" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1542355159.371" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1542355159.371" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1655961586.888" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1655961586.888" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1655961586.888" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1655961586.888" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803

Deprecated: Implicit conversion from float-string "1544784517.327" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1544784517.327" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1544784517.327" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1544784517.327" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803
1.1k
views
0 answers
0 votes
Swapnil Naik asked Nov 16, 2018
1,121 views
In Reader-writer problem, if a Writer is writing some data, can other reader reads the data at the same time?If no, this is the code present in Galvin how does it taking ...
415
views
1 answers
0 votes
Rackson asked Dec 14, 2018
415 views
Please describe the Deadlock Condition in synchronization and when will be synchronization possible and condition ..?