Visualized multi-threaded simulators in Ruby
summary
A visualized petrol‑station simulator implemented in MRI Ruby uses a custom shared timer plus mutexes, condition variables and queues to run pumps as consumer threads while a car spawner lazily yields arrivals from a YAML scenario. It runs many simulations in parallel (tested >10) without one thread per car, compares setups like 3 pumps @3s/L versus 6 pumps @6s/L and picks the highest‑revenue scenario (example: simulation 8 wins), and renders results live with d3.js and ASCII art.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 5:31Petrol station scenarios
- 7:15Logger and timer
- 11:36YAML configuration
- 13:42Car spawner and queue
- 16:33Ruby thread conditions
- 18:57Lessons learned
- 21:47Future ideas
- 23:18Resources
related talks
44mSimulating the World with Ruby
33mConcurrency for !Dummies (Who Don't Get It (...Yet))
28mConcurrency for Rubyists
23mParallel Processing With Ruby
30mStupid Ideas For Many Computers
20mSubprocesses, Threads and Fibers
54mConcurrency: Rubies, plural
38m"Parallel and Thread-Safe Ruby at High-Speed with TruffleRuby"
