AMX Semaphore Manager
K
A
DAK
91
6. AMX Semaphore Manager6.1 Introduction
E.W. Dijkstra introduced two primitive operations to resolve two seemingly unrelated
problems: mutually exclusive access by tasks to critical resources and the
synchronization of asynchronously occurring activities.
The abstract primitives, called P and V operators, operate on a variable called a
semaphore. Many variations of these P and V operators have been implemented since
their first introduction. The AMX Semaphore Manager provides two variations: a
counting semaphore which has been enhanced to provide priority queuing and automatic
timeout, and a resource semaphore in which resource ownership is tied to a specific task.
A counting semaphore is a semaphore with an associated counter which is incremented
by the P operator (signal) and decremented by the V operator (wait). The resource
(object) controlled by the semaphore is free (available) when the counter is greater
than 0. The number of resources (objects) controlled by the semaphore is determined by
the maximum value the counter is allowed to achieve.
A counting semaphore with a maximum count of one is a binary semaphore. It can be
used to provide mutually exclusive access to a single resource or to signal a particular
event.
A resource semaphore is a binary semaphore which can only be used for resource
ownership control. It differs from a counting semaphore in one significant feature:
resource ownership is tied to a specific task. No other task except the task owning the
resource is allowed to signal the release of the resource.
The counting and resource semaphores provided by the Semaphore Manager have been
enhanced to provide priority queuing and automatic timeout. Tasks which wait on
semaphores can specify the priority at which they wish to wait for the resource or event
controlled by the semaphore. Tasks can also specify the maximum interval which they
are prepared to wait.
The AMX Semaphore Manager provides the following semaphore management services:
ajsmcre AASMCRE Create a semaphore
ajsmdel AASMDEL Delete a semaphore
ajsmrsv AASMRSV Reserve a resource semaphore (optional timeout)
ajsmrls AASMRLS Release a resource semaphore (nested)
ajsmfre AASMFRE Free a resource semaphore (unconditional)
ajsmwat AASMWAT Wait on a counting semaphore (optional timeout)
ajsmsig AASMSIG Signal to a counting semaphore
ajsmget AASMGET Get use of a counting semaphore (no wait)
ajsmtag AASMTAG Find the semaphore id of a semaphore with a specific tag