Generally speaking, Lock protects a shared state, and Condition used to wait for a specific condition in that state.
But in your task, you actually have two sets of orthogonal states - elevator states and floor states. This means that if you want to use the Lock / Condition primitives to work with this task, you need to create separate locks and conditions for these states.
That is, when the elevator rises to the floor, it acquires its own lock and floor lock, and then signals the condition associated with the floor, so that visitors waiting on the floor wake up. Also pay attention to the lock order to avoid locks in this scheme.
axtavt
source share