AMX Semaphore Manager
K
A
DAK
101
Resource Nesting
Assume that two tasks, A and B, have to share a numeric coprocessor. Furthermore,
these two tasks also must share a common library procedure ncmath which must use the
coprocessor.
A resource semaphore must be used because ownership of the numeric coprocessor must
be tied to one task at a time and the owner must be allowed to make nested resource
reservation calls.
In the example, Task A waits indefinitely (timeout value = 0) at priority level 20 for the
use of the numeric coprocessor. Once the task owns the coprocessor, it initializes it and
calls ncmath to perform some mathematical operation using it. Task A then finishes
using the coprocessor and releases it.
Task B does not use the coprocessor directly. It calls ncmath to perform a mathematical
operation which requires the use of the coprocessor.
The math library procedure waits forever at priority 20 to reserve the coprocessor without
knowing which task is calling. If ncmath is called by Task B while Task A owns the
coprocessor, Task B will be suspended by the Semaphore Manager until Task A is
finished with the coprocessor.
The manner in which Tasks A and B are created and started is beyond the scope of this
example.
For simplicity, Tasks A and B do not check the error codes returned by ncmath or the
Semaphore Manager. In practice, error codes should never be ignored.