Reader-Writer: Wikipedia Page On The Subject
Reader-Writer: Wikipedia Page On The Subject
Reader-Writer
This problem has been extensively studied since the ’60s, and
is often categorized into three variants:
Unfortunately, only the solutions for the first two problems are
easily found on the Internet. As of today, even the wikipedia
page on the subject does not have an algorithm for what is called
“the third readers-writers problem”. However, this algorithm is
very simple once you decompose the problem into smaller steps
and properties.
void reader()
{
P(orderMutex); // Remember our order of arrival
...
V(orderMutex); // Released when the reader can access the
resource
...
}
void writer()
{
P(orderMutex); // Remember our order of arrival
...
V(orderMutex); // Released when the writer can access the
resource
}
void reader()
{
P(orderMutex); // Remember our order of arrival
...
V(orderMutex); // Released when the reader can access the
resource
...
}
void writer()
{
P(orderMutex); // Remember our order of arrival
P(accessMutex); // Request exclusive access to the resource
V(orderMutex); // Release order of arrival semaphore (we have
been served)
void reader()
{
P(orderMutex); // Remember our order of arrival
void writer()
{
P(orderMutex); // Remember our order of arrival
P(accessMutex); // Request exclusive access to the resource
V(orderMutex); // Release order of arrival semaphore (we have
been served)
Lab 12
Practice Task
Task1:
Implement & validate the algorithm of the 1st reader-writer
problem.
Task2:
Modify the Task1 to maintain order in which the readers or
writers arrive and make it starvation-free.
Task3:
Modify the Task1 such that Readers and Writers go their critical
section in an alternative order. Not more than 5 readers can
enter their critical sections.
If there are 8 readers and 3 writer threads, five readers go
their critical section and when they all exit one writer enters
its critical section. Upon exit of the writer, the next 3 reader
threads then enter their critical sections.