title: Is it safe to use a global variable to mark executing in ISR
body: <p>I know that different architectures may provide different ways to let developer detect whether the cpu is running in ISR now, e.g. reading a register.</p>
  
  <p>But I do found that in some BSP code, they use a global variable,it is called <code>g_in_isr</code>, as a flag to indicating whether cpu running in ISR. When an interrupt occurred the interrupt handler will perform <code>g_in_isr++</code> operation on entery and <code>g_in_isr--</code> on exit.</p>
  
  <p>I am wondering if this way is safe on the architectures which allows nested interrupt. In most architectures, <code>g_in_isr++</code> or <code>g_in_isr--</code> is not atomic operation (am I right?), what if an high priority interrupt comes while an existing interrupt handler is doing <code>g_in_isr++</code> operation? Doesn't it cause problems?</p>
  
  <p><strong>Update (2016-03-27)</strong></p>
  
  <p>Yeah, I know it is architecture dependent, but I want to know the general case. Let us assume that <code>g_in_isr++</code> is not atomic, it is indeed not atomic on most architecture, am I right? Of course we also don't use any compiler magic to make it atomic.</p>
  
  <p>Now at such a case, would it cause problems?</p>