Top 10 Computer Science multithreading exercises to practice.
-
Race Condition Multiple threads increment a shared counter without synchronization, leading to incorrect results.
-
Deadlock Two threads each hold a lock and wait for the other's lock, causing a permanent hang.
-
Starvation A low-priority thread never gets CPU time because a high-priority thread dominates.
-
Livelock Two threads keep reacting to each other but neither makes progress.
-
Producer-Consumer Coordinating a producer and consumer with a bounded buffer using
wait()/notifyAll(). -
Readers-Writers Multiple readers can read simultaneously, but a writer needs exclusive access.
-
Dining Philosophers 5 philosophers compete for 5 shared forks; demonstrates resource contention and potential deadlock.
-
Barrier / Rendezvous All threads must reach a synchronization point before any can proceed, using
CyclicBarrier. -
Thread Pool Exhaustion A fixed-size thread pool is overwhelmed by long-running tasks, causing new tasks to queue up.
-
Memory Visibility One thread's changes aren't visible to another due to CPU caching; demonstrates
volatileas the fix.