µC/OS-III supports a special type of binary semaphore called a mutual exclusion semaphore (also known as a mutex) that eliminates unbounded priority inversions. The figure below shows how priority inversions are bounded using a Mutex.
Panel |
---|
borderWidth | 0 |
---|
title | Using a mutex to share a resource |
---|
|
|
...
µC/OS-III enables the user to nest ownership of mutexes. If a task owns a mutex, it can own the same mutex up to 250 times. The owner must release the mutex an equivalent number of times. In several cases, an application may not be immediately aware that it called OSMutexPend()
multiple times, especially if the mutex is acquired again by calling a function as shown in in Listing 13-12.
Anchor |
---|
| Listing 13-12 |
---|
| Listing 13-12 |
---|
|
...
There are a number of operations that can be performed on a mutex, as summarized in the table below. However, in this chapter, we will only discuss the three functions that are most often used: OSMutexCreate()
, OSMutexPend()
, and OSMutexPost()
. Other functions are described in µC-OS-III API Reference.
Panel |
---|
|
Function Name | Operation |
---|
OSMutexCreate() | Create a mutex. | OSMutexDel() | Delete a mutex. | OSMutexPend() | Wait on a mutex. | OSMutexPendAbort() | Abort the wait on a mutex. | OSMutexPost() | Release a mutex. |
|