1. First Problem – Reader Priority
2. Second Problem – Writer Priority
3. Third Problem – No Starvation (Fair)
Size: 37.47 KB
Language: en
Added: May 10, 2025
Slides: 12 pages
Slide Content
Reader Writer Problem Operating Systems By Rinku Monani
Introduction • A problem that deals with synchronization. • Involves a data set shared among concurrent processes. • Two types of processes: readers and writers. • Readers only read; writers update or write. • Important to maintain data consistency.
Sharing of Data • Allow multiple readers simultaneously. • Only one writer at a time. • A writer must have exclusive access.
Active Readers and Writers • If one writer is writing, no other process (reader or writer) can access the data. • If one or more readers are reading, no writer can access the data. • Multiple readers can read simultaneously.
Types of Reader Writer Problem 1. Reader Priority 2. Writer Priority
Reader Priority • Multiple readers can read at the same time. • Writer must wait until readers finish. • Problem: Writer starvation.
Writer Priority • Writers given priority over readers. • Once a writer is waiting, no new readers are allowed. • Problem: Reader starvation.
Semaphores • Semaphore is a synchronization tool. • Can be used to control access to shared resources.
Semaphore Definitions • readcount – number of readers currently reading. • mutex – controls access to readcount. • wrt – allows writers exclusive access to the data.
Structure of Reader Process // Reader wait(mutex) readcount++; if (readcount == 1) wait(wrt); signal(mutex) [Reading is performed] wait(mutex) readcount--; if (readcount == 0) signal(wrt); signal(mutex)
Structure of Writer Process // Writer wait(wrt) [Writing is performed] signal(wrt)