Last updated
Last updated
The reader-writer problem is a classic synchronization problem in concurrent programming that involves two types of processes: readers and writers. These processes access a shared resource, such as a database or a file, under certain constraints. The problem can be summarized as follows:
Readers: Multiple readers can access the shared resource simultaneously without any issues. They only read the resource and do not modify it. Readers can access the resource concurrently as long as no writer is currently writing to it.
Writers: Writers are exclusive; only one writer can access the resource at a time. Writers have the authority to modify the shared resource. While a writer is writing to the resource, no other readers or writers are allowed access.
The primary goals of the reader-writer problem are:
Allow multiple readers to access the resource concurrently for reading (readers-writers concurrency).
Ensure exclusive access for writers to prevent multiple writers from modifying the resource simultaneously (writers-writers mutual exclusion).
Avoid the possibility of writers starving, meaning that if a writer is waiting to access the resource, it should eventually get a chance, even if new readers keep arriving (fairness).
Mutex : Binary semaphore to ensure mutual exclusion , when read count ( rc ) is updated
wrt : Binary Semaphore common for both reader and writer , to maintain mutual exclusion between reader & writer.
read count ( rc ) : interger , to keep record of how many readers are there
Writer :
Reader :