Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C language Readers-Writer Problem (Semaphores) For this task, you will implement a solution to Readers-Writers problem. Prompt the user for R , W , and

C language

Readers-Writer Problem (Semaphores)

For this task, you will implement a solution to Readers-Writers problem. Prompt the user for R, W, and N, where R is the number of readers, W is the number of writers, and N is the max number of readers that can read the file at once. You must use semaphores to control file access when attempting to read/write the file.

Procedure

After prompting the user for R, W, and N, fork several threads equal to the number of readers and writers that access a file to read or write. There is no need to actually read or write to a file, wait for some cycles or do some work to represent read/write latency.

Readers only read the information from the file and does not change file contents. Writers can change the file contents. The basic synchronization constraint is the any number of readers should be able to access the file at the same time, but only one writer can write to the file at a time (without any readers).

For this task, the design should be such that N readers read, 1 writer writes, N readers read, 1 writer writes and so on. If a reader or writer is not available at a time, your solution must wait until they become available and the pattern must be maintained. Yield is not allowed for this task.

sample output

Readers Writers Problem Enter Readers : 10 Enter Writers : 3 Enter Max_Readers count between 1 and 10: 2 R0 started reading. R1 started reading. -R1 finished reading. Total Reads:1 -R0 finished reading. Total Reads:2 --W1 started writing ---W1 finished writing R3 started reading. R2 started reading. -R2 finished reading. Total Reads:1 -R3 finished reading. Total Reads:2 --W2 started writing ---W2 finished writing R4 started reading. R5 started reading. -R4 finished reading. Total Reads:1 -R5 finished reading. Total Reads:2 --W0 started writing ---W0 finished writing R6 started reading. R7 started reading. -R6 finished reading. Total Reads:1 -R7 finished reading. Total Reads:2

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

Accounting Ethics

Authors: Ronald F. Duska, Brenda Shay Duska, Kenneth Wm. Kury

3rd Edition

1119118786, 9781119118787

More Books

Students also viewed these Accounting questions

Question

LO6 Describe how to choose among the recruitment sources.

Answered: 1 week ago