Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Void BeginRead () // A reader can enter if there are no writers // active or waiting, so we can have / many readers active
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 Variable:s Time in Second InitiallyNone Procedure executed None Condition variable queues Process NWriters NReaders CanRead CanWrite 0 false empty empty 0 R1 BeginRead 1 Algorithm's premises Can Readers access the data along with some active Writers? .Is it true that writers can access database only when there are no readers or writers? How many threads can manipulate the state variables at a time? . Understanding the solution This algorithm wants to be fair - explain! The code is "simplified" because we know there can only be one writer at a time, What other assumption are made here to make this code simple
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