title: Kernel: Dealing with deadlocks in unix
body: <blockquote>
    <p>A <strong>deadlock</strong> would occur if process 1 locks <strong>resource A</strong> and waits for
    <strong>resource B</strong>, while simultaneously (due to context switches at the "right" places) process 2 locks <strong>resource B</strong> and waits for access to <strong>resource 
    A</strong>.</p>
  </blockquote>
  
  <p>How does Unix deal with such deadlocks? I read the following <strong><a href="http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/avoid-race.html" rel="nofollow">here</a></strong>.</p>
  
  <blockquote>
    <p>Many deadlocks can be prevented by simply requiring all processes that
    lock multiple resources to lock them in the same order (e.g.,
    alphabetically by lock name)</p>
  </blockquote>
  
  <p>How can it <strong>change the order</strong> in which locks are acquired without also changing the execution order? 
  Could someone <strong>detail</strong> the approach to deadlock-handling taken by the modern Unix kernel?</p>