Question: Refer to the Readers Writers problem shown in the code below. typedef struct _ rwlock _ t { sem _ t lock; / / binary

Refer to the Readers Writers problem shown in the code below.
typedef struct _rwlock_t {
sem_t lock; // binary semaphore (basic lock)
sem_t writelock; // allow ONE writer/MANY readers
int readers; // #readers in critical section
rwlock_t;
void rwlock_init(rwlock_t *rw)
rw->readers =0;
sem_init(&rw->lock, 0,1);
sem_init(&rw->writelock, 0,1);
}
void rwlock_acquire_readlock(rwlock_t *rw){
sem_wait(&rw->lock);
rw->readers++;
if (rw->readers ==1)// first reader gets writelock
sem_wait (&rw->writelock);
sem_post(&rw->lock);
}
void rwlock_release_readlock(rwlock_t *rw){
sem_wait (&rw->lock);
rw->readers--
if (rw->readers ==0)// last reader lets it go
sem_post (&rw->writelock);
sem_post(&rw->lock);
}
void rwlock_acquire_writelock(rwlock_t *rw){
sem_wait(&rw->writelock);
}
void rwlock_release_writelock (rwlock_t *rw){
sem_post(&rw->writelock);
}
A Writer process W1 starts its execution and currently is in Critical Section (CS) after the steps 1,2 and 3 occur in order.
Step 1: Writer process W2 is trying to access CS
Step 2: Reader process R1 is trying to access CS
Step 3: Reader process R2 is trying to access CS
What is the final value of semaphore variable lock, writelock, and variable readers (You MUST show
your work; template to show the work)
Refer to the Readers Writers problem shown in the

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 Programming Questions!