This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Atomic Operations in C



Hello!


I'm setting a status variable in the ISR and in the main loop. In assembler the OR operation is atomic.

Is the OR Operation in C also atomic?

here is may example:

volatile int my_status = 0;

void main(void) {

...
    my_status |= BIT7;
}

void isr(){
    my_status |= BIT0;
}

Do I need to disable the ISR in the main?

-Thomas

  • Thomas,

    There is no guarantee that the compiler will generate a single atomic read-modify-write instruction.

    The exception would be if you made use of a few intrinsics that map directly to the read-modify-write instructions (__and, __or and __xor - documented in www.ti.com/lit/SPRU514).

    In the ISR, interrupts are disabled automatically when the ISR is taken.

    Regards
    Lori