Skip to content
All work
Systems

Cars, buses, a mutex, and two condition variables.

C++ implementation; the demo simulates the same rules.

C++pthreadsCondition variablesTypeScript (demo)
Bridge simulator: vehicles queued at a single-lane bridge with condition-variable waiters

Overview

A pthreads simulation of a single-lane bridge where cars and buses are threads. At most two cars may cross together, a bus crosses alone, and the two never share the bridge.

Interactive demo

Up to two cars at a time, or one bus alone. Toggle the original wake-up logic to reproduce its lost-wake-up stall, then switch to the fixed version.

Limitations

  • On exit, a bus signals only the bus condition variable and a car broadcasts only to cars, so a bus waiting behind cars is never woken. The direction input is read but never used.