Lecture 13: Synchronization 4 Flashcards
“Readers/Writers Problem”
“Idea:
You have a buffer of updatable data (i.e.: no inserts & removes)
Threads:
Two kinds:
1. Readers
2. Writers
• some concurrency ok: multiple readers reading data
some concurrency not ok: writer must have exclusive
access to data
Synchronization rules:
Can allow access of:
• any number of readers at a time, or
• exactly one writer”
Solving with Semaphores:
“Basic Idea:
• binary semaphore (rwlock)
+
count of readers (rcount)
• 1st read acquires rwlock (rcount = 1)
• last reader releases rwlock (rcount = 0)
• need additional binary semaphore (mutex) to ensure exclusive access to rcount”