title: In Linux, polling in a conscientious way
body: <p>When you've got a tight loop polling the status of something, I'm not quite sure how to do the polling without getting in the way of other processes wanting to use the CPU. For instance, doing this:</p>
  
  <pre><code>while (state == BUSY) state = check_state();
  </code></pre>
  
  <p>seems like a waste of resources. I would think the best way to do this would be:</p>
  
  <pre><code>while (state == BUSY) {
      sched_yield();
      state = check_state();
  }
  </code></pre>
  
  <p>I'd expect that top would list the process as sleeping, even if it does consume 100% of the CPU while it's doing this. This way, the process would (I hope) poll "nicely". But that's not what happens. At the moment I have</p>
  
  <pre><code>while (state == BUSY) {
      sleep(1);
      state = check_state();
  }
  </code></pre>
  
  <p>which is perfectly acceptable, but I feel like it could be done better than this. Is there a standard practice for doing this?</p>