Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following code of a monitor that is designed to solve the readers/writers problem in FCFS order while maintaining exclusive write and concurrent read:

Given the following code of a monitor that is designed to solve the readers/writers problem in FCFS order while maintaining exclusive write and concurrent read:

RW : monitor;

begin

readercount : integer;

busy : boolean;

FCFS_Q, write_Q : condition;

procedure startread;

begin

if busy OR FCFS_Q.queue OR write_Q.queue then FCFS_Q.wait;

readercount := readercount + 1;

FCFS_Q.signal;

end startread;

procedure endread;

begin

readercount := readercount -1;

if readercount = 0 then

if write_Q.queue then write_Q.signal

else FCFS_Q.signal;

end endread;

procedure startwrite;

begin

if busy OR readercount 0 OR FCFS_Q.queue then FCFS_Q.wait;

if readercount 0 then write_Q.wait;

busy := true;

end startwrite;

procedure endwrite;

begin

busy := false;

if FCFS_Q.queue then FCFS_Q.signal;

end endwrite;

begin /* Main program of the monitor, used for initialization */

readercount := 0;

busy := false;

end;

end RW;

Suppose the above monitor is used to control the access to a shared file among a number of readers and writers. Assume that the sequence of arrivals of processes that require access to the shared resource be: R1, W1, R2, R3, W2. Here R1, R2, R3, W1, and W2 are processes that are in existence concurrently. For simplicity, assume further the following:

These arrivals are 1 second apart.

Each of the monitor procedure takes 1 second to execute (not counting the time in queue). For simplicity, you may assume 1 second even when only part of the procedure gets executed.

Each operation, read or write, takes 5 seconds.

All processes that require access to the shared file will follow the 3-step procedure:

Reader: call RW.startread; read; call RW.endread.

Write: call RW.startwrite; write; call RW.endwrite.

Note: The time durations provided above are to enable you to determine the approximate timing of events. Leave an entry in the table below blank when there is no change.

Time in

Process

Procedure

Variables

Condition variable queues

Process removed

Second

executed

readercount

busy

FCFS_Q

write_Q

from any queue

Initially

None

None

0

false

empty

empty

None

0

R1

startread

1

Given the following code of a monitor that is designed to solve the readers/writers problem in FCFS order while maintaining exclusive write and concurrent read:

RW : monitor;

begin

readercount : integer;

busy : boolean;

FCFS_Q, write_Q : condition;

procedure startread;

begin

if busy OR FCFS_Q.queue OR write_Q.queue then FCFS_Q.wait;

readercount := readercount + 1;

FCFS_Q.signal;

end startread;

procedure endread;

begin

readercount := readercount -1;

if readercount = 0 then

if write_Q.queue then write_Q.signal

else FCFS_Q.signal;

end endread;

procedure startwrite;

begin

if busy OR readercount 0 OR FCFS_Q.queue then FCFS_Q.wait;

if readercount 0 then write_Q.wait;

busy := true;

end startwrite;

procedure endwrite;

begin

busy := false;

if FCFS_Q.queue then FCFS_Q.signal;

end endwrite;

begin /* Main program of the monitor, used for initialization */

readercount := 0;

busy := false;

end;

end RW;

Suppose the above monitor is used to control the access to a shared file among a number of readers and writers. Assume that the sequence of arrivals of processes that require access to the shared resource be: R1, W1, R2, R3, W2. Here R1, R2, R3, W1, and W2 are processes that are in existence concurrently. For simplicity, assume further the following:

These arrivals are 1 second apart.

Each of the monitor procedure takes 1 second to execute (not counting the time in queue). For simplicity, you may assume 1 second even when only part of the procedure gets executed.

Each operation, read or write, takes 5 seconds.

All processes that require access to the shared file will follow the 3-step procedure:

Reader: call RW.startread; read; call RW.endread.

Write: call RW.startwrite; write; call RW.endwrite.

Note: The time durations provided above are to enable you to determine the approximate timing of events. Leave an entry in the table below blank when there is no change.

Time in

Process

Procedure

Variables

Condition variable queues

Process removed

Second

executed

readercount

busy

FCFS_Q

write_Q

from any queue

Initially

None

None

0

false

empty

empty

None

0

R1

startread

1

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

Students also viewed these Databases questions

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago