CSE 330 – Operating Systems

CSE 330 – Operating Systems
Fall 2019
Project 4
No late Submission Accepted
Readers and Writers
Using the semaphores you have implemented, implement the Readers and Writers Problem.
Test case
Have a global variable int i and set it to 0 initially
The readers should read the variable value and print the current value of the variable. Each
reader should print the variables twice. The writers should write their ids in the variable. The
writer should write in one go and then verify that the correct Id is written into the variable.
Readers and writers do not run in infinite loop but reader reads twice while writer writes and
then again verifies.
The reader yields after one read and then finishes after the second read.
On the first read the reader prints
Printf(“This is the %d the reader reading value i = %d for the first time”, readerID, i );
On the second read the reader prints
Printf(“This is the %d the reader reading value i = %d for the second time”, readerID, i );
The writer yields after the first write and then exits after the verification step.
On the first write the writer prints
Printf(“This is the %d the writer writing value i = %d ”, writerID, i );
On the verification loop the writer should write
Printf(“This is the %d the writer verifying value i = %d ”, writerID, i );
Have 5 readers then a writer then 4 readers then 2 writers then 5 readers then 1 writer and
then 3 readers.
Assignment 4 expected output
This is the 1 th reader reading value i = 0 for the first time
This is the 2 th reader reading value i = 0 for the first time
This is the 3 th reader reading value i = 0 for the first time
This is the 4 th reader reading value i = 0 for the first time
This is the 5 th reader reading value i = 0 for the first time
This is the 1 th reader reading value i = 0 for the second time
This is the 2 th reader reading value i = 0 for the second time
This is the 3 th reader reading value i = 0 for the second time
This is the 4 th reader reading value i = 0 for the second time
This is the 5 th reader reading value i = 0 for the second time
This is the 1 th writer writing value i = 1
This is the 1 th writer verifying value i = 1
This is the 6 th reader reading value i = 1 for the first time
This is the 7 th reader reading value i = 1 for the first time
..
..
This is the 17 th reader reading value i = 1 for the first time
This is the 6 th reader reading value i = 1 for the second time
This is the 7 th reader reading value i = 1 for the second time
..
..
This is the 16 th reader reading value i = 1 for the second time
This is the 17 th reader reading value i = 1 for the second time
This is the 2 th writer writing value i = 2
This is the 2 th writer verifying value i = 2
This is the 3 th writer writing value i = 3
This is the 3 th writer verifying value i = 3
This is the 4 th writer writing value i = 4
This is the 4 th writer verifying value i = 4

Leave a Reply

Your email address will not be published. Required fields are marked *