Question: The reader-writer problem can be stated as follows: A shared memory location can be concurrently read by any number of tasks, but when a task must write to the shared memory location, it must have exclusive access.
Write a Java program that creates 3 threads each of them performing 10 reading/writing to the shared location. Use a random number generator to decide if the request is reading or writing (say, 0 for reading, 1 for writing.) Before each action, print out "thread i now ready to read (or write) the shared location", after the action, print out "thread i now finished read (or write) the shared location". Here i could be 0, 1, or 2.
Can you prepare a program to prepare the threads to read and write to a shared location?