True or false: After a condition-variable wait returns, a thread can assume that the condition it was waiting for is true.
5 Concurrency and Synchronization Online Quiz Questions
Use this free practice quiz with 20 questions to review 5 Concurrency and Synchronization, test your knowledge, and prepare for your next test or exam.
A parallel computation has several stages, and no thread should start the next stage until every thread has finished the current one. Which synchronization primitive best fits this requirement?
- A
To let multiple readers examine shared data while excluding all writers permanently
- B
To let one thread wait until a shared queue becomes nonempty
- C
To make a group of threads wait until all have reached the same stage
- D
To represent a pool of several identical available resources
A counting semaphore has a count of 7. Three threads each successfully acquire it once, and no thread releases it. What is the count afterward?
In a bounded-buffer system, producers should when the buffer is full, while consumers should when it is empty.
Two threads increment a shared counter without synchronization. Each increment consists of reading the counter, adding one, and writing the result. Which outcome is possible?
- A
The counter is guaranteed to increase twice because each thread executes an increment statement.
- B
Both threads may read the same old value and then write the same new value, losing one increment.
- C
The operating system must terminate one thread because simultaneous writes are impossible.
- D
The counter will decrease because each thread overwrites the other thread's read.
What synchronization property requires that a thread requesting entry to a critical section cannot be bypassed forever by other threads?
Threads repeatedly respond to one another but make no useful progress. This situation is an example of deadlock.
- A
True
- B
False
In the dining-philosophers problem, requiring everyone to acquire forks in a can prevent the circular wait that leads to deadlock.
A shared data structure is read frequently and updated occasionally. The design should allow multiple readers at once but exclude readers while a writer holds the lock. Which primitive best matches this access pattern?
- A
A mutex, because it allows all readers to access the data simultaneously
- B
A read-write lock, because it can allow multiple readers while excluding readers when a writer holds the lock
- C
A barrier, because it grants writers exclusive access to shared data
- D
A counting semaphore, because it automatically prevents writers from being delayed
Which practices support safer synchronization in a concurrent program? Select all that apply.
- A
Define which lock guards each piece of shared state.
- B
Keep a lock held while waiting for unrelated work, so the protected state cannot change.
- C
Release locks promptly when the protected work is complete.
- D
Test concurrent programs under varied timing.
- E
Avoid waiting for unrelated work while holding a lock.
Which conditions must all hold for the classic resource deadlock described in operating-systems theory? Select all that apply.
- A
Mutual exclusion
- B
Hold and wait
- C
A safe state for every possible resource allocation
- D
No preemption
- E
Circular wait
A system designer is comparing deadlock prevention, avoidance, and detection and recovery. Explain how each approach handles the possibility of deadlock, including what avoidance must know before granting a resource request.
A single-core operating system switches between two threads, allowing each to make progress during overlapping periods. Which statement best describes this situation?
- A
Concurrency requires multiple processor cores.
- B
The operating system can interleave threads so they make progress during overlapping periods.
- C
Concurrency occurs only when threads access the same shared variable.
- D
A single-core system runs all threads simultaneously.
A service has a pool of four identical connections and must limit how many threads use them at once. Which approach directly matches this requirement?
- A
A mutex initialized to four permits four simultaneous holders.
- B
A condition variable initialized to four permits four threads to skip checking a predicate.
- C
A counting semaphore initialized to four can limit access to four connections.
- D
A barrier initialized to four provides exclusive access to four connections.
A thread waits on a condition variable for a shared queue to become nonempty. What should it do after waking?
- A
Recheck the predicate in a loop after waking.
- B
Treat the wake-up as proof that the predicate is true.
- C
Unlock the mutex before checking the predicate for the first time.
- D
Replace the predicate with a fixed delay.
In a bounded-buffer producer–consumer system, under which conditions should producers and consumers wait?
- A
Producers wait when the buffer is empty; consumers wait when it is full.
- B
Both producers and consumers wait only when the buffer is empty.
- C
Consumers wait when the buffer is full; producers wait when it is empty.
- D
Producers wait when the buffer is full; consumers wait when it is empty.
A shared data structure is read frequently and updated less often. Which read-write-lock behavior can support this pattern?
- A
It permits multiple writers at once but only one reader.
- B
It permits multiple readers at once and excludes readers while a writer holds the lock.
- C
It forces every reader and writer to wait until all other threads terminate.
- D
It allows readers to update data while a writer holds the lock.
If no thread is in a critical section and some threads want to enter, the progress property rules out postponing the choice of the next entrant indefinitely.
- A
True
- B
False
Two threads repeatedly respond to each other's actions, but neither makes useful progress. What is this problem called?
A parallel computation is divided into phases, and each group of threads must wait until all threads reach the same stage before proceeding. What synchronization primitive supports this?