Module: Rainbows::WorkerYield
- Included in:
- ThreadSpawn
- Defined in:
- lib/rainbows/worker_yield.rb
Overview
:enddoc:
Instance Method Summary collapse
-
#worker_yield ⇒ Object
Sleep if we’re busy (and let other threads run).
Instance Method Details
#worker_yield ⇒ Object
Sleep if we’re busy (and let other threads run). Another less busy worker process may take it for us if we sleep. This is gross but other options still suck because they require expensive/complicated synchronization primitives for every case, not just this unlikely one. Since this case is (or should be) uncommon, just busy wait when we have to. We don’t use Thread.pass because it needlessly spins the CPU during I/O wait, CPU cycles that can be better used by other worker processes.
13 14 15 |
# File 'lib/rainbows/worker_yield.rb', line 13 def worker_yield sleep(0.01) end |