ARM Development Tools

Thread-Safe Features of Keil RTOS and Middleware

All Keil RTOS and Middleware libraries are thread-safe. This ensures all library code will run correctly during simultaneous execution by multiple threads. All processes can access shared data and multiple instances of library functions without the risk of undefined behaviour.

Thread-Safe Operation
Multiple tasks can safely call multiple library functions simultaneously.

Thread-safety in the middleware libraries is implemented by using a combination of methods:

Mutual exclusion control mechanisms such as semaphores ensure that deadlocks and race-conditions are avoided by limiting access to shared data. A new task may have to wait for a previous process to complete operation before it is allowed to use the shared resource.

Thread specific storage of variables means that there is no possible corruption of data across thread or sub-routine boundaries and ensures consistent RTX kernel operation.

Reentrant implementations of library routines allow a function that is partially completed in a stalled task to be safely called and re-entered from another task. Every instance of a re-entrant function is capable of saving and restoring its own execution status to ensure all instances will complete as expected regardless of interruptions. Standard library functions are not re-entrant by default.

Example of Reentrant Operation
Multiple threads may call the same function simultaneously (click for larger diagram).

Thread-safe operation is a key factor in providing a robust and versatile operating system such as RTX. All Keil middleware components are written to be thread safe which means you can take advantage of this feature when using Flash, TCPnet USB or CAN with the RTX kernel.