Question: A file is shared between several reader and writer threads. Design a monitor to control the access of the file by the different threads so

A file is shared between several reader and writer threads. Design a monitor to control the access of the file by the different threads so that the following constraints are satisfied: (i) at most one writer can be active on the file at a particular time. (ii) When a writer is writing to the file, no reader can read from the file. (iii) More than one reader can be reading from the file simultaneously. (iv) When a writer is waiting to write, no more new reader should be allowed to read. (v) When a writer is writing and some other writer is waiting to write, then the writer is given more preference over a reader waiting to read. The general structure of each reader and writer thread is shown in the following: Monitor FileControl { // Definition of the monitor class to be filled in by you } FileControl fc; // An instance of the monitor Writer Thread: Reader Thread: while (True) { while (True) { ... ... fc.WriterEntry(); fc.ReaderEntry(); Write (file); Read (file); fc.WriterExit(); fc.ReaderExit(); } } Fill in the pseudo-code for the monitor FileControl as shown above.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!