AMX Semaphore Manager
K
A
DAK
93
6.2 Semaphore Use
The Semaphore Manager supports any number of semaphores. The maximum number of
semaphores in a system is defined in your System Configuration Module (see Chapter
14.5). The defined maximum sets an upper limit on the number of actual semaphores
that can be created in your application.
A semaphore must be created by an application before it can be used. Restart
Procedures, tasks, ISPs and Timer Procedures can create semaphores. It is recommended
that only Restart Procedures and tasks be used to create semaphores.
A semaphore is created with a call to procedure ajsmcre indicating the type of
semaphore, counting or resource, to be created. The Semaphore Manager allocates a
semaphore and returns a semaphore id to the caller. The semaphore id is a handle which
uniquely identifies the semaphore. It is the responsibility of the application to keep track
of the semaphore id for future reference to the semaphore.
When a semaphore is created, you can provide a unique 4-character tag to identify the
semaphore. The tag can be used subsequently in a call to ajsmtag to find the semaphore
id allocated by the Semaphore Manager to the particular semaphore.
When a semaphore is no longer needed, it can be deleted with a call to ajsmdel. The
Semaphore Manager will reject the attempt to delete the semaphore if any task is waiting
for the use of the semaphore. When the Semaphore Manager deletes a semaphore, it
marks the semaphore as invalid such that any subsequent reference to the semaphore will
be rejected.
You must be absolutely certain that no task, ISP or Timer Procedure is referencing the
semaphore just as you go to delete it. Be aware that the deleted semaphore id may
immediately be reused by AMX for some other purpose.