GDSX Manual

Service Routines
Extended General Device Support (GDSX) Manual134303
8-41
INIT^SEM
INIT^SEM
This procedure initializes a semaphore other than the checkpoint semaphore in either
global or extended memory.
The purpose of a semaphore is to ensure the serial access of a shared resource. A task is
considered to have acquired a resource when it owns the semaphore associated with the
resource. TSCODE defines and maintains a checkpoint semaphore to guarantee that no
more than one task is doing a checkpoint at any given time.
A unique user-defined semaphore should be established for each resource requiring
exclusive access. Three utility procedures are available for managing noncheckpoint
semaphores:
INIT^SEM
PSEM
VSEM
The checkpoint semaphore is defined by TSCODE and managed with the GET^CPSEM
and GIVE^CPSEM procedures.
A semaphore is first initialized with INIT^SEM. The semaphore can be defined in
global or extended memory; however, it is recommended that it is declared in global
memory, within a user private block, for example. If a backup GDSX process exists, the
semaphore must be initialized in both primary and backup GDSX processes. The
semaphore may then be acquired by calls to PSEM and released by calls to VSEM.
A task takes control of a semaphore when a call to PSEM inserts the address of the
task’s TCB (@TCB) into the first element of the semaphore structure (described in the
table below). If the semaphore is already owned, a task requesting ownership has its
TCB address inserted at the end of a linked list of tasks waiting for the same resource
(tasks are linked by tcb.locklink). The linked list is also part of the semaphore structure,
which has three elements.
Variable Name Description Contents
sem.semowner Current owner of semaphore 0 if semaphore is available; owner’s TCB
if semaphore is owned
sem.semhead Head of the wait list Address of SEMHEAD if no tasks are
waiting; otherwise, first waiter’s TCB
address
sem.semtail Tail of the wait list Address of SEMHEAD if no tasks are
waiting; otherwise, last waiter’s TCB
address
CALL INIT^SEM ( semaphore ); !
i