In the ucos-II operating system, if the real-time kernel is not used, it needs to be agreed to test a whole variable first. If the variable is 0, tasks are allowed to process shared resources. To prevent another task from using the resource, the former simply sets the whole variable to 1, which is often called test and set, or TAS. TAS operation may be a single instruction of the microprocessor that will not be interrupted, or it may be to close the interrupt in the program to do TAS operation and then open the interrupt.
The program list is as follows:
Disable interrupts; Turn off interrupt
If the resource is unavailable, If ('accessvariable' is 0) {flag is 0.
Set the variable to1; Settings resource is not available, marked as 1.
Re-enable interrupts; Reopen the interrupt
Access resources; Processing resources
Disable interrupts; Turn off interrupt
Set the Access Variable back to 0; The Clear resource cannot be used, and the flag is 0.
Re-enable interrupts; Reopen the interrupt
} else {otherwise.
Re-enable interrupts; suspend
/* You don't have permission to access resources. Please try again later. */
/* Resources are unavailable, please try again later. */
}