Question
C++ Version 2 In most cases, we would like updates to take place as soon as possible. This version will favor writers. Your implementation should
C++
Version 2 In most cases, we would like updates to take place as soon as possible. This version will favor writers. Your implementation should allow readers to enter the critical section until a writer arrives. When a reader arrives and a writer is waiting, the reader should be suspended behind the writer instead of being allowed to enter the critical region immediately. A writer will need to wait until all readers that are active in the critical region are finished but should not wait for readers that arrived after its arrival. If more than one writer is waiting, all writers should be allowed to write before any readers are allowed to read again.
Implementation Notes for Version 2 All of the implementation notes for version 1 apply to version 2. Use the Pthreads (POSIX threads) for condition variables. In addition to printing the thread type, thread number, value read, and the number of readers present in the critical region when the value is read, readers must print: o The number of readers waiting o The number of writers waiting Sample output: reader 1 read 71 1 reader(s), 1 reader(s) waiting, 1 writer(s) waiting In addition to printing the thread type, thread number, value written, and the number of readers present in the critical region when the value is read, readers must print: o The number of readers waiting o The number of writers waiting writer 2 wrote 192 0 reader(s), 1 reader(s) waiting, 0 writer(s) waiting
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