Class/Module Index

MonitorMixin

In concurrent programming, a monitor is an object or module intended to be
used safely by more than one thread. The defining characteristic of a
monitor is that its methods are executed with mutual exclusion. That is,
at each point in time, at most one thread may be executing any of its
methods. This mutual exclusion greatly simplifies reasoning about the
implementation of monitors compared to reasoning about parallel code that
updates a data structure.

You can read more about the general principles on the Wikipedia page for Monitors

The consumer thread waits for the producer thread to push a line to buf
while buf.empty?. The producer thread (main thread) reads a
line from ARGF and pushes it into buf then calls
empty_cond.signal to notify the consumer thread of new data.