- count++ is load–increment–store; interleaving these steps from two processes can lose an update.
- Race condition: the result depends on the order in which processes access shared data.
🎯 How this can come up · 1 question
A situation where the outcome depends on the order of access to shared data is a:
Correct: Race condition.
- Critical section: the code that touches shared data. Structure: entry section, critical section, exit section, remainder section.
- Requirements: Mutual exclusion (one at a time), Progress (no needless waiting when the CS is free), Bounded waiting (no starvation).
🎯 How this can come up · 1 question
Which is NOT a requirement of a critical-section solution?
Correct: Preemption.
- Peterson’s solution (2 processes): shared turn and flag[2]. Pᵢ sets flag[i] = true, turn = j, then waits while flag[j] && turn == j.
- Hardware support: atomic (uninterruptible) instructions such as test_and_set and compare_and_swap.
- test_and_set returns the old value and sets the lock to true, in one atomic step.
- Semaphore S: integer accessed only by wait() (P: decrement, block if < 0) and signal() (V: increment, wake one).
🎯 How this can come up · 1 question
wait(S) on a semaphore:
Correct: Decrements S and may block.
- Binary semaphore (0/1) = mutex lock. Counting semaphore controls access to N instances; initialize it to N.
🎯 How this can come up · 1 question
A counting semaphore guarding 5 identical printers should be initialized to:
Correct: 5.
- Busy waiting (spinlock) wastes CPU; better implementation blocks the process on the semaphore’s waiting list.
- Deadlock: each process waits for an event only another waiting process can cause. Starvation: indefinite blocking.
🎯 How this can come up · 1 question
P0 runs wait(S); wait(Q); and P1 runs wait(Q); wait(S); with S = Q = 1. What can happen?
Deadlock: P0 gets S, P1 gets Q, then each waits forever for the semaphore the other holds.
- Bounded buffer: mutex = 1, full = 0, empty = n. Producer: wait(empty); wait(mutex); … signal(mutex); signal(full).
🎯 How this can come up · 1 question
In the bounded-buffer solution with n slots, empty starts at:
Correct: n.
- Readers–writers: many readers may read together; a writer needs exclusive access. rw_mutex = 1, mutex = 1, read_count = 0.
- Dining philosophers: one semaphore per chopstick can deadlock if all pick up the left one at once.
🎯 How this can come up · 1 question
Which avoids deadlock in dining philosophers?
Also: pick up both only if both are free, or odd/even asymmetric ordering.
- Semaphore misuse: signal before wait, wait twice, or forgetting one → broken mutual exclusion or deadlock.
- Monitor: high-level construct; only one process active inside at a time.
- Condition variables: x.wait() suspends the caller; x.signal() resumes one waiting process (no effect if none).
No slides match this filter.












