Skip to the content of the web site.

Binary semaphores and mutual exclusion

The application of the equivalent of a binary semaphore to achieve mutual exclusion (mutex) and simple signalling is described in the RL-ARM user's guide under Mutex Management Routines. In this implementation, the word release is used to describe the posting of the mutual exclusion, as the token is being released to the next requesting task.

As described in class, this implementation uses priority inheritance to solve the priority inversion problem.

To view the source code for the semaphore implementation, see Keil\ARM\RL\RTX\SRC\ARM\rt_Mutex.c.

Note: if you are interestd at looking at the CMSIS-RTOS implementation of mutex, please see the CMSIS-RTOS API page on mutex management. Unlike the Keil RTX RTOS, it includes functions for creating, waiting on, releasing and deleting mutual exclusions. The Keil RTX RTOS likely assumes you are using their RTOS in a situation that does not require the dynamic creation and destruction of mutual exclusions.

Note that the CMSIS-RTOS API is meant to be cross-platform for all Cortex-M processors. Consequently, the implementation is based strongly on using the pre-processor #define directive allowing for platform-specific implementations of these macros.

In both cases, the mutal exclusion is initialized with one token available. If you want to have no tokens available, you must use a counting semaphore.