[SOLVED] Multi-threaded C program for readers/writers problem

15.00 $

Categories: , Tags: , , , ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Reader-Writer.zip (0.9 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (2 votes)

Write a multi-threaded C program for readers/writers problem using Pthreads. This program should adhere to the following constraints:

1. Multiple readers/writers must be supported (at least 4 of each type);

2. Readers must read the shared variable multiple times (at least 4 times);

3. Writers must write the shared variable multiple times (at least 4 times);

4. Readers must print:

a. The reader thread ID,

b. The value of the shared variable,

c. The number of readers present when value is read;

5. Writers must print:

a. The writer thread ID,

b. The written value to the shared variable,

c. The number of readers present were when value is written.

The print out can be implemented using fprintf(). A sample code can be found in readerswriters.c. Before a reader/writer attempts to access the shared variable, it should wait some random amount of time. This will help ensure that reads and writes do not occur all at once. For this purpose, you can use srandom() and usleep().

  • Reader-Writer.zip