Guardian Programmer's Guide

Table Of Contents
Synchronizing Processes
Guardian Programmer’s Guide 421922-014
26 - 8
Forcing a Lock on a Binary Semaphore
BINSEM_ISMINE_ returns a nonzero value if the SEMID is valid and the calling
process currently has that binary semaphore locked.
Forcing a Lock on a Binary Semaphore
Under certain conditions you may want to force a lock on a binary semaphore that is
currently locked by another process. For example, a process holding a lock may have
entered an infinite loop or some other unresponsive state. To force a lock on a binary
semaphore, call the BINSEM_FORCELOCK_ procedure.
The BINSEM_FORCELOCK_ procedure enables a process to take a lock away from
another process. However, the original process continues to run as though it still has
the lock, so to avoid possible conflicts, you should take steps to terminate that process.
In order to force a lock on a binary semaphore, a process must have permission to
access the binary semaphore, as specified in the BINSEM_CREATE_ call that created
the binary semaphore.
Closing a Binary Semaphore
Once a process is finished executing critical sections of code, it should close any
binary semaphores that it has open. To close a binary semaphore, call the
BINSEM_CLOSE_ procedure.
A process typically calls BINSEM_CLOSE_ at the end of its execution. After closing a
binary semaphore, the process no longer has knowledge of it and can no longer
request a lock on it. Once all processes that have opened a binary semaphore close it,
any resources used by the semaphore are returned to the system.
When a process terminates, any binary semaphores it has open are automatically
closed. If any are locked by the process at the time of termination, they become
forsaken, as described earlier under Locking a Binary Semaphore.
Binary Semaphore Interface Declarations
As of the J06.14 and H06.25 RVUs, the entire binary semaphore interface is defined in
two new header files: KBINSEM for TAL/epTAL and KBINSEMH (also referred to as
kbinsem.h) for C/C++. These headers include literals for options and result codes,
the output structure for BINSEM_GETSTATS_, and the version literals for
BINSEM_STAT_VERSION_. In all supported releases, six of the BINSEM_...
procedures continue to be declared in EXTDECS* and CEXTDECS. The three newer
procedures, BINSEM_ISMINE_, BINSEM_GETSTATS_, and
BINEM_STATS_VERSION_, are declared only in KBINSEM and kbinsem.h.
The kbinsem.h file also contains type definitions and macros to manage the process
handle parameters required by two of the procedures: BINSEM_GETSTATS_ and
Note. The BINSEM_FORCELOCK_ call should be used only in critical situations, because it
circumvents the protection that binary semaphores are designed to provide.