Rainbows! 3.1.0 - minor updates
[rainbows.git] / lib / rainbows / worker_yield.rb
blobe81d35820accfd61aa63c9040c14c0ac8200dddb
1 # -*- encoding: binary -*-
2 # :enddoc:
3 module Rainbows::WorkerYield
5   # Sleep if we're busy (and let other threads run).  Another less busy
6   # worker process may take it for us if we sleep. This is gross but
7   # other options still suck because they require expensive/complicated
8   # synchronization primitives for _every_ case, not just this unlikely
9   # one.  Since this case is (or should be) uncommon, just busy wait
10   # when we have to.  We don't use Thread.pass because it needlessly
11   # spins the CPU during I/O wait, CPU cycles that can be better used by
12   # other worker _processes_.
13   def worker_yield
14     sleep(0.01)
15   end
16 end