Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions