C language Readers-Writer Problem (Semaphores) For this task, you will implement a solution to Readers-Writers...
90.2K
Verified Solution
Link Copied!
Question
Accounting
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
Answer & Explanation
Solved by verified expert
Get Answers to Unlimited Questions
Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!
Membership Benefits:
Unlimited Question Access with detailed Answers
Zin AI - 3 Million Words
10 Dall-E 3 Images
20 Plot Generations
Conversation with Dialogue Memory
No Ads, Ever!
Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!