title: Ruby infinite loop causes 100% cpu load
body: <p>I implemented some code, which runs in a loop:</p>
  
  <pre><code>loop do
     ..
  end
  </code></pre>
  
  <p>In that loop, I handle keypresses with Curses library. If I press N and entered something, I start a new Thread, which counts time( <code>loop do .. end</code> again)</p>
  
  <p>The question is, why <code>loop</code> or <code>while true</code> causes 100% cpu load on one of the cpu cores? Is the problem actaully in loop?</p>
  
  <p>Is there a way to do infinite loop with lower cpu consumption in ruby?</p>
  
  <p>The full sources available <a href="https://github.com/Baldrs/track-me" rel="nofollow">here</a></p>
  
  <p><strong>UPD - Strace</strong></p>
  
  <pre><code>$ strace -c -p 5480
  Process 5480 attached - interrupt to quit
  ^CProcess 5480 detached
  % time     seconds  usecs/call     calls    errors syscall
  ------ ----------- ----------- --------- --------- ----------------
  51.52    0.002188           0    142842           ioctl
  24.21    0.001028           0     71421           select
  14.22    0.000604           0     47614           gettimeofday
  10.05    0.000427           0     47614           rt_sigaction
  0.00    0.000000           0        25           write
  0.00    0.000000           0        16           futex
  ------ ----------- ----------- --------- --------- ----------------
  100.00    0.004247                309532           total
  </code></pre>