Question
Synchronization- Semaphore Provide a scenario that shows the following policy gives priority to writers. In your scenario, you should have two readers and a writer.
Synchronization- Semaphore
Provide a scenario that shows the following policy gives priority to writers. In your scenario, you should have two readers and a writer.
reader() { while(TRUE) { ; P(writePending); P(readBlock); P(mutex1); readCount++; if(readCount == 1) P(writeBlock); V(mutex1); V(readBlock); V(writePending); access(resource); P(mutex1); readCount--; if(readCount == 0) V(writeBlock); V(mutex1); } } int readCount = 0, writeCount = 0; semaphore mutex1 = 1, mutex2 = 1; semaphore readBlock = 1, writeBlock = 1, writePending = 1; fork(reader, 0);/* could be many */ fork(writer, 0);/* could be many */ | writer() { while(TRUE) { ; P(mutex2); writeCount++; if(writeCount == 1) P(readBlock); V(mutex2); P(writeBlock); access(resource); V(writeBlock); P(mutex2) writeCount--; if(writeCount == 0) V(readBlock); V(mutex2); } } |
Time Action Result
0 Reader 1 arrives
1 Reader 1 executes P (writePending) writePending = 0
2 Reader 1 executes P (readBlock) readBlock = 0
Fill in the rest of the operations steps
(the answers i have so far
3 Reader 1 executes P (mutex)_ m1=0
4 Reader 1 executes readcount++ rc=1
5 Reader 1 executes p(write block) wb=0
6 Reader 1 executes v(mutex1) m1=1
7 Reader 1 executes v(read block rb=1
8 Reader 1 executes v(write pending) wp=1
9 Reader 1 executes access(resource)
10 Reader 1 is interrupted
11 W1 arrrives
)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started