Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Recall the Readers/Writers problem: readers processes query a database and writer processes examine and modify it. Readers may access the database concurrently, but writers require
Recall the Readers/Writers problem: readers processes query a database and writer processes examine and modify it. Readers may access the database concurrently, but writers require exclusive access. Although the database is shared, we cannot encapsulate it by a monitor, because readers could not then access it concurrently since all code within a monitor executes with mutual exclusion. Instead, we use a monitor merely to arbitrate access to the database. The database itself is global to the readers and writers. In the Readers/Writers problem, the arbitration monitor grants permission to access the database. To do so, it requires that processes inform it when they want access and when they have finished. There are two kinds of processes and two actions per process, so the monitor has four procedures: request_read, release_read, request_write, release_write. These procedures are used in the obvious ways. For example, a reader calls request_read before reading the database and calls release_read after reading the database. To synchronize access to the database, we need to record how many processes are reading and how many processes are writing. In the implementation below, nr is the number of readers, and nw is the number of writers; both of them are initially 0 . Each variable is incremented in the appropriate request procedure and decremented in the appropriate release procedure. A beginner software developer has implemented this code, but has unfortunately missed a lot of details related to synchronization. Help the beginner developer fix this code
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