Katkat

Design synchronization for water molecule assembly

TeslaSoftware Engineer · HR Screen

Last 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.