AMX Semaphore Manager
K
A
DAK
97
6.3 Semaphore ApplicationsMutual Exclusion
Assume that three tasks, A, B and C, require shared access to a common data stru cture
being used to control some process. Access to the data structure must be mutually
exclusive so that one task cannot be modifying the data in the structure while another task
is accessing it.
A semaphore with an initial count of one is required because there is only one data
structure to manage. A counting semaphore is created in a Restart Procedure and
initialized with a count of one. One task can own the resource; two tasks can be waiting.
Note that the Semaphore Manager does not guarantee that only tasks A, B and C can
access the data structure.
In this example, Task A waits indefinitely (timeout value = 0) at priority level 20 for
access to the data variable. Task B waits indefinitely at priority level 10. Task C only
waits for 100 system ticks at priority 5 before it assumes that it cannot have the resource.
This example is illustrated on the next page. The manner in which Tasks A, B and C are
created and started is beyond the scope of this example.
Parameters 1 and 2 in the data structure are modified by the tasks to illustrate that their
alteration by one task is guaranteed by the semaphore to be completed before access by
either of the other two tasks is allowed.