Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Assignment 3. Monitor The task here requires analysis of the following algorithm concerning the monitor. // STATE VARABLES /7 Number of active readers; initially0

image text in transcribedimage text in transcribedimage text in transcribed

Lab Assignment 3. Monitor The task here requires analysis of the following algorithm concerning the monitor. // STATE VARABLES /7 Number of active readers; initially0 int NReaders 0; // Number of waiting readers; initially = 0 int WaitingReaders0 // Number of active writers; initially int NWriters 0 0 7Number of waiting writers initially 0 int WaitingWriters0 Condition canRead = NULL; Condition canWriteNULL Void BeginWrite) /A writer can enter if there are no other // active writers and no readers are waiting if (NWritersNReaders > 0) ++WaitingWriters; wait (CanWrite); --WaitingWriters; NWriters = 1; Void EndWrite () NTT iters = 0; /7 Checks to see if any readers are waiting if (WaitingReaders) Signal (CanRead); else Signal (CanWrite); Void BeginRead () // A reader can enter if there are no writers // active or waiting, so we can have / many readers active all at once if (NWriters1 WaitingWriters > 0) ++WaitingReaders; /7 Otherwise, a reader waits (maybe many do) Wait (CanRead) --WaitingReaders; ++NReaders; Signal (CanRead); Void EndRead () // When a reader finishes, if it was the last reader, // it lets a writer in (if any is there). if (-NReaders0) Signal (CanWrite); Analysis 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, and when the procedure resumes execution another second will be used 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 BeginRead(l; Read(); call EndRead) Write: call BeginWrite); Write(); call EndWrite() YOUR task is to complete the table below and answer the following questions. 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 Second Initially None Procedure executed None BeginRead Variables Condition variable queues Process NWriters NReaders Can Read CanWrite 0 false empty empty 0 R1

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Persuading Your Audience Strategies for

Answered: 1 week ago