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
  • Even with 8-bit variables, you can have problems with atomic operations.

    For example:

    ticket = next_ticket++;
    

    In this case, both the assign of the "ticket" variable, and the increment of "next_ticket" may be required to be performed in an unbroken sequence if there are more than one task - or a task and an interrupt - that needs to check out tickets.

    The above is similar to sempaphores and other synchronizing constructs where you may need an atomic test + write or test + increment or similar. Most modern processors have at least one special instruction for such purpose.

Reply
  • Even with 8-bit variables, you can have problems with atomic operations.

    For example:

    ticket = next_ticket++;
    

    In this case, both the assign of the "ticket" variable, and the increment of "next_ticket" may be required to be performed in an unbroken sequence if there are more than one task - or a task and an interrupt - that needs to check out tickets.

    The above is similar to sempaphores and other synchronizing constructs where you may need an atomic test + write or test + increment or similar. Most modern processors have at least one special instruction for such purpose.

Children
No data