posted 10 years ago
The following program (ReaderOrWriter class) that implements the readers-writers problem with semaphores.
The main program (not shown) creates many reader and writer threads, starts each of them, and then waits forever for them to terminate by calling each thread’s join() method.
What values should each of the semaphores be initialized to?
s: ??
okToRead: ??
okToWriteL ??
How can I tell what is the semaphore value just by looking at the codes?
Assume a reader is currently using the buffer. If there are both waiting writers and waiting readers, will a writer or a reader get access to the buffer first?
Is it possible for readers to starve with this code?
Can the semaphore okToRead have a value greater than 1?
Can the semaphore okToWrite have a value greater than 1?