Concurrency Patterns Quiz

Q1. Concurrency means tasks run at the exact same time on multiple CPU cores.


Q2. Using immutable objects in a multi-threaded program can help prevent race conditions.


Q3. Which of the following describes a race condition in a concurrent program?




Q4. A deadlock can happen if two threads each hold a lock and are waiting to acquire the other thread’s lock.


Q5. Which of the following is NOT a thread-safe practice for incrementing a shared counter from multiple threads?




Q6. In a classic Producer-Consumer scenario with a fixed-size buffer, how can we prevent the producer from overfilling the buffer or the consumer from reading an empty buffer?




Q7. Which concurrency pattern is characterized by splitting a task into subtasks that run in parallel and then joining the results?




Q8. Which statement is true about futures and promises?




Q9. In the Actor model of concurrency, which of the following is true?




Q10. Which concurrency pattern reuses a fixed pool of worker threads to execute tasks from a queue?




Q11. What is a key difference between a mutex (lock) and a counting semaphore?




Q12. Two threads each perform counter++ 1000 times without synchronization. What is a possible final value of the counter?




Q13. Thread 1 acquires Lock X then Lock Y, while Thread 2 acquires Lock Y then Lock X. What concurrency issue can occur?




Q14. Starvation is a situation where a thread never gets the CPU time or resources it needs to make progress.


Q15. Adding more threads to a program will always improve performance.


Q16. A lock-free algorithm guarantees that overall progress is always made without using mutual-exclusion locks.


Q17. In a livelock, two or more threads are actively running and responding to each other, yet no thread is making forward progress.


Q18. Which of the following is NOT one of Coffman’s four necessary deadlock conditions?




Q19. What is a common strategy to prevent deadlocks when a program must acquire multiple locks?




Q20. Typically, a Future is a read-only placeholder for a result supplied later, whereas a Promise is a write-once object used to provide that result.


design-patterns