Concurrency control Flashcards
What is the bounded-buffer/producer-consumer problem?
Process produces data, process consumes data.
Production and consumption rates may vary - shared buffer absorbs variations
What is the dining philosophers?
Share a round table, need two chopsticks to eat. Pick up closest chopstick one at a time, no-one eats = deadlock.
What is the Reader and writers problem?
DB shared between processes, in which one PS reads and the other writes. Reader may read partially written data.
What is a critical section?
Part of a program that accesses shared data.
Must ensure that only one process can be executing in a critical section at a given time.
How do we avoid race conditions?
Design a protocol for process cooperation.
lock
critical section
unlock
How can we avoid race conditions?
- Atomic instructions
- Interrupts
- Kernel scheduler
- Concurrency control mechanisms
How do Atomic Instructions help to avoid race conditions?
HW support for implementing lock, acquire lock on entry and release lock on exit
How do we prevent concurrency?
Single processor: Disable interrupts during wait and signal operations
Multiple processors: Secondary mutual exclusion algorithm, involves busy waiting.
Basically, spin when there’s nothing to do
What is a semaphore?
Used to implement different synchronisation mechanisms.
Can avoid busy-waiting
How do binary semaphores work?
Integer restricted to 0 or 1.
Known as a mutex
How do counting semaphores work?
Starts with amount of resources and decrements/increments when they are removed/readded
What are the atomic operations
Wait: Delays the calling process integer > 0, then decrements it
Signal: Increment integer
What is special about a mutex?
It is shared between all cooperating processes.
How are bounded-buffers used concurrently?
Mutual exclusion on the buffer pool, can’t be read & written simultaneously. Synchronised when buffer is empty or full.
How do we get R/W concurrency
Mutual exclusion for writers, as many readers as wanted.