Programming 2 with Java

Exercise: Readers/Writers Problem

A number of concurrent threads require access to the same resource (such as a file). The readers read information from the resource, and the writers write information into it. Many readers may access the resource simultaneously, but if a writer is accessing the resource, no other threads may access it. The problem is to avoid that readers or writers starve.

Readers/Writers

Implement the class Resource of the ReadersWriters program that simulates the readers/writers problem.

Solution