This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Atomicity

Is the operation below an atomic operation in a multitasking environment like RTX-51? If it is not, then what is supposed to do to make it an atomic one except using locking mechanisms?

void func()
{
  int locVal = globalVal++;
  ...
  ...
}

Parents
  • Most processors don't have any hardware support for atomic operations, so the compiler would have to disable interrupts.

    Unfortunately that only moves the problem elsewhere, but doesn't solve it. The trouble being that in general you have to save the previous state of the interrupt-enable flag before you disable interrupts, so you can clean up after yourself. In order for that saved state to be valid, these two operations have to be combined into an atomic step.

    I.e. you need an atomic instruction to work around the lack of an atomic instruction. Chicken/Egg, here we come!

Reply
  • Most processors don't have any hardware support for atomic operations, so the compiler would have to disable interrupts.

    Unfortunately that only moves the problem elsewhere, but doesn't solve it. The trouble being that in general you have to save the previous state of the interrupt-enable flag before you disable interrupts, so you can clean up after yourself. In order for that saved state to be valid, these two operations have to be combined into an atomic step.

    I.e. you need an atomic instruction to work around the lack of an atomic instruction. Chicken/Egg, here we come!

Children