We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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++; ... ... }
so, only operations which are converted into a single instruction in machine level are atomic I was not clear, I should have posted like this: If it the variable operated on is more than 8 bits long
One last question: what do you mean by saying "processed at different process levels"? processed in main and an ISR or processed in 2 different ISRs ...
Erik
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.