What is a monitor, and how do condition variables with wait() and signal() differ from semaphores?

Last updated 5 July 2026

  • A monitor bundles shared data with its procedures and guarantees only one thread runs inside at a time, so no manual locking is needed.

  • Condition variable wait() releases the monitor lock and blocks. signal() wakes one waiter but is lost if no one is waiting, unlike a semaphore whose count remembers it.

  • Under Mesa semantics (Java, pthreads) the signaler keeps running, so waiters must recheck the condition in a while loop. Hoare semantics hand the monitor to the woken thread immediately.

  • https://www.geeksforgeeks.org/operating-systems/monitor-vs-semaphore/
  • https://dev.to/ishitajuneja/what-is-a-monitor-and-semaphore-2lga
  • https://www.geeksforgeeks.org/operating-systems/difference-between-semaphore-and-condition-variable/
  • https://www.tutorialspoint.com/article/difference-between-semaphore-and-monitor-in-os
  • https://medium.com/@drajput_14416/synchronization-superheroes-condition-variables-and-semaphores-explained-411c5ee43738
All Operating Systems interview questions