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.