System thread


ATOMIC_BLOCK() is similar to SINGLE_THREADED_BLOCK() in that it prevents other threads executing during a block of code. In addition, interrupts are also disabled.

WARNING: Disabling interrupts prevents normal system operation. Consequently, ATOMIC_BLOCK() should be used only for brief periods where atomicity is essential.

   // code here is executed atomically, without task switching
   // or interrupts of a lower priority than this thread

Here's an example:

void so_timing_sensitive_and_no_interrupts()
    if (ready_to_send) {
           ATOMIC_BLOCK() { 
        // only this code runs from here on - no other threads or interrupts
            digitalWrite(D0, LOW);
            digitalWrite(D0, HIGH);
    }  // other threads and interrupts can run from here