threading — Concurrency for I/O-Bound Work — Concept Check
Questions on threading — Concurrency for I/O-Bound Work. ThreadPoolExecutor turns "call 50 slow APIs one by one" into "call them together" — and Lock protects the shared state that threads would otherwise corrupt.
Questions in this quiz
7 questions on threading — Concurrency for I/O-Bound Work — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer uses ThreadPoolExecutor to make 10 API calls. Each call takes 1 second. How long will it take to complete all calls?
- AApproximately 0.1 second
- BApproximately 5 seconds
- CApproximately 10 seconds
- DApproximately 1 second
2.You notice that a counter variable is not reaching its expected value when incremented by multiple threads. What could be the issue?
- ARace condition due to lack of synchronization
- BCounter variable is immutable
- CThreads are not running concurrently
- DThreadPoolExecutor is not used
3.A developer uses threading.Lock to protect a shared variable. What is the benefit of this approach?
- AIt prevents deadlocks in all cases
- BIt ensures atomic operations on the variable
- CIt eliminates the need for a ThreadPoolExecutor
- DIt increases the execution speed of threads
4.In a multithreaded program, what could cause updates to a shared variable to be lost?
- AThreadPoolExecutor is used incorrectly
- BThreads are running on a single core
- CThreads interleave operations without locks
- DThreads use queue.Queue for communication
5.What happens if you comment out the lock in a function incrementing a shared counter in multiple threads?
- AThe program will run faster
- BThe final counter value will be unpredictable
- CThe counter will always reach its expected value
- DThe program will deadlock
6.A developer uses ThreadPoolExecutor but notices that tasks are not completing faster than sequential execution. What might be wrong?
- ATasks are CPU-bound, not I/O-bound
- BTasks are too short
- CInsufficient number of worker threads
- DThreadPoolExecutor is not suitable for any tasks
7.When using pool.submit + as_completed, how are results handled?
- AResults are ordered by input sequence
- BResults are yielded as they finish
- CResults are processed in reverse order
- DResults are discarded if not retrieved immediately