title: Operating System: Isn't it a wrong practice to switch to another process with the interrupt blocked?
body: <p>I saw this piece of code on disk read in Linux 0.11 kernel:</p>
  
  <pre><code>static inline void lock_buffer(struct buffer_head * bh)
  {
      cli();
      while (bh-&gt;b_lock)
          sleep_on(&amp;bh-&gt;b_wait);
      bh-&gt;b_lock=1;
      sti();
  }
  </code></pre>
  
  <p>IIUC, <code>cli()</code> will block the interrupt (not blocking all as explained here: <a href="https://c9x.me/x86/html/file_module_x86_id_31.html" rel="nofollow noreferrer">https://c9x.me/x86/html/file_module_x86_id_31.html</a>, but still, block some interrupts which means it changes the default behavior).</p>
  
  <p>And <code>sleep_on</code> will call <code>schedule</code>, which will pass the control flow to another process.</p>
  
  <p>However, what makes me confused is that here we will switch to another process with some of the interrupts blocked, which seems error-prone because the other process should expect the default behavior. So is this a correctly written piece of code (if so, why?) or it is just a wrongly written one which will cause unexpected behaviors?</p>