Anonymous · shared experience20 Sept 2025 · 6 views
Informatica: Two threads printing odd and even numbers in order
Problem. Start two threads. One prints odd numbers and the other prints even numbers, and together they must print 1, 2, 3, 4 and so on in order.
Context. It came in a round that also asked about race conditions, synchronization and the volatile keyword, for a Java role.
What to prepare. A shared counter guarded by a lock with wait and notify, or a pair of semaphores that hand turns back and forth. Explain why volatile alone is not enough to keep the order.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.