Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Reader - Writers Problem of Threads with Locks / Semaphores The reader - writer problem is used to illustrate synchronization for threads that's are
The ReaderWriters Problem of Threads with LocksSemaphores The readerwriter problem is used to illustrate synchronization for threads that's are reading
and writing to a shared file. Readers read files but do not update files, Writers read and update
files. In the readerwriters problem, multiple readers can read at the same time but only ONE
writer can be allowed to write to the file.
Whe
The readerwriter problem is used to illustrate synchronization for threads thats are reading
and writing to a shared file. Readers read files but do not update files, Writers read and update
files. In the readerwriters problem, multiple readers can read at the same time but only ONE
writer can be allowed to write to the file.
When thread writes, no other threads can write.
When thread writes, no other threads can read.
When thread reads, no other threads can write.
When thread reads, other threads can read ONLY.
Mutex Locks and Semaphores can be used to carry out the synchronization of readers and
writers in this problem.
Create your algorithm to execute the readerwriters problem with locks to control reading and
writing to ONE shared file.
There are universal control variables
Mutex semaphore : ensure mutual exclusion when readcount is updated
Writemutex: mutual exclusion lock for writers
Readcount : keep track of how many processes are currently reading object
The implementation be written in C or C
For your program, there should be at least functions, the Check function is up to you to
implement whether separately or in the ReadWrite
Wait
When a reader or writer needs to acquire the Mutex Semaphore or Writemutex
If a reader allowed to read, ReadCount as to be incremented
Signal
When a reader or writer finishes reading and writing, the Mutex Semaphore or
Writemutex should be released
If a reader finishes reading, ReadCount should be decremented
Read
If a reader wants to read, it has to check whether any writer is writing to the file.
If there are writers writing, readers are not allowed to read.
If there are no writing done then readers can read. Before reading, readers have
to Wait to increment ReadCount
Write
If a writer wants to write, it has to check whether any writer is writing to the file
or whether any readers are reading the file. If there are writers writing or readers
reading, the writer is not allowed to write.
If there are no writing or reading done then writers can write. Before writing,
writers have to Wait to use the Writemutex.
Check
Check whether readers finish reading, Signal to decrement ReadCount
Check whether writers finish writing, Signal to release Writemutex.
Inputs:
Read Write function
Finish Not Finish writing
Finish Not Finish Reading
Outputs:
Allowed Not Allowed to Write
Allowed Not Allowed to Read
Any Writer writing
Number of Readers reading
You are currently accessing A file.
Are you a Readerr or Writerw Type e to exit. w
You are a Writer.
Writing allowed.
write mutex on
running apain
Are you a Readerr or Writer Type e to exit. r
You are a Reader.
Reading not allowed. Writer is writing.
Is the Writer done writing
Writer done. Please proceed again
r running again
Are you a Readerr or Writer Type e to exit. r
x You are a Reader.
Reading allowed.
mutex on
read count:
running again
Are you a Readerr or Writerw Type e to exit. e
Process exited after seconds with return value
Press any key to continue
Your program design do not need to be the same but should have proper notification and
warnings. Your output should also be able to show the state and response of the program.
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