System Thread

ATOMIC_BLOCK()

ATOMIC_BLOCK

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.

// SYNTAX
ATOMIC_BLOCK() {
   // code here is executed atomically, without task switching
   // or interrupts
}

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);
            delayMicroseconds(50);
            digitalWrite(D0, HIGH);
            }
    }  // other threads and interrupts can run from here
}