title: Possible deadlock situation: interrupt and mutex
body: <p>I have this C++ program, which eventually falls apart in two threads. One thread waits for an interrupt, and if it happens it will increment a counter:</p>
  
  <pre><code>void reactInterrupt(){
      counter_lock.lock();
      std::cout&lt;&lt; ++counter;
      counter_lock.unlock();
  }
  </code></pre>
  
  <p>The interrupt code comes from <a href="http://wiringpi.com/reference/priority-interrupts-and-threads/" rel="nofollow">wiringPi</a>
  There is also the seconds thread, which sleeps for x seconds and when it wakes up, it does the following:</p>
  
  <pre><code>//blaaah
      int coutercopy;
      counter_lock.lock();
      countercopy = counter;
      counter = 0;
      counter_lock.unlock();
  //more blaah
  </code></pre>
  
  <p>Now I am extremely curious: what would happen if the mutex was being locked by the second thread on the moment an interrupt would happen. How deep does the interrupt go? Does it completely lock everything while it is trying to finish the reactInterrupt() code? Because if that is the case, I see an (extremely rare) deadlock situation where the CPU would just wait indefenitly for the mutex to become unlocked. Or does the interrupt merely schedule the method for execution, which would only mean the the method is being added to the list of things the CPU has to do? In that case the method would just wait for the mutex to become free, which I would think is much nicer.</p>