Hi,
This is the reader-writer problem for just read consistency. Here is the algorithm,
void reader() {
while (1){
P(mutex);
rc++;
if (rc == 1) P(db); /* <---- A */
V(mutex); /* <---- B */
read_data_base();
P(mutex):
rc--;
V(mutex);
if (rc ==0) V(db);
}
}
void writer() {
while(1) {
P(db);
write_data_base();
V(db);
}
}
Here is my Question : 1. What is the purpose of line A in the leader code? 2. Can we eliminate that line and the code work correctly?