Question: 1. Here are the codes for the reader-writer The structure of a writer process do { wait(rw_mutex); ... /* writing is performed */ ... signal(rw_mutex);

1. Here are the codes for the reader-writer

The structure of a writer process

do { wait(rw_mutex);

... /* writing is performed */

...

signal(rw_mutex);

} while (true);

The structure of a reader process

do { wait(mutex); read count++; if (read_count == 1)

wait(rw_mutex);

signal(mutex);

... /* reading is performed */

...

wait(mutex); read count--; if (read_count == 0)

signal(rw_mutex);

signal(mutex);

} while (true);

Shared Data

Data set

Semaphore rw_mutex initialized to 1

Semaphore mutex initialized to 1

Integer read_count initialized to 0

Assume: currently there is a Reader process R1 that is reading the data; firstly a Writer process W1 comes and then another Reader process R2 comes; what W1 and R1 will do? Please explain your answer based on the code

Answer:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!