Skip to main content

Checkpoint: bounded buffer with dual conditions

Challenge on lesson: Checkpoint: The Bounded Buffer

Implement static List<Integer> runBuffer(): 1. Inside Solution, build a bounded buffer (capacity 2) with ReentrantLock + two Conditions (notFull, notEmpty) and internal ArrayDeque<Integer>. 2. Producer virtual thread: puts 1..5 (await notFull while full; signal notEmpty after each put). 3. Consumer virtual thread: takes 5 values (await notEmpty while empty; signal notFull after each take). 4. runBuffer() starts both, waits for the consumer's 5 values, and returns them in take-order. 5. static String casAlternative() returns exactly: "a CAS loop on an index pair could do it, but Condition queues express the wait logic more clearly".

Difficulty: advanced

Back to lesson: Checkpoint: The Bounded Buffer