Design synchronization for water molecule assembly
TeslaSoftware Engineer · HR ScreenLast updated
This question evaluates concurrency and synchronization skills, including thread coordination, use of locks/semaphores/condition variables, and reasoning about safety and liveness properties in concurrent systems.
Multiple threads repeatedly provide 'H' and 'O' atoms as callable actions. Design synchronization so that the program outputs a valid sequence representing water molecules, where for every molecule exactly two 'H' actions and one 'O' action are released together. Do not busy-wait; use semaphores/locks/condition variables. Ensure safety (no extra atoms), liveness (no starvation), and scalability under an unbounded stream of atoms. Provide pseudocode and explain correctness.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.