Guardian Programmer's Guide

Table Of Contents
Synchronizing Processes
Guardian Programmer’s Guide 421922-014
26 - 12
Procedure SECONDARY
Procedure SECONDARY
Procedure SECONDARY is executed by the secondary process. That process shares
the segment created by the primary process, and passes to SECONDARY a pointer to
the shared structure. It opens the binary semaphore, locks the binary semaphore,
uses the shared resource, unlocks the binary semaphore, and closes the binary
semaphore. The main process handle and the semaphore ID are picked up from the
shared structure. Procedure SECONDARY is as follows:
PROC SECONDARY (SHARED);
INT .EXT SHARED (SHARED_TEMPLATE);
BEGIN
INT ERROR;
INT(32) SECONDARYSEMID;
ERROR := BINSEM_OPEN_ (SECONDARYSEMID,
SHARED.MAINPROCESSHANDLE,
SHARED.MAINSEMID);
IF (ERROR <> 0) THEN CALL DEBUG;
CALL USERESOURCE (SECONDARYSEMID);
ERROR := BINSEM_CLOSE_ (SECONDARYSEMID);
IF (ERROR <> 0) THEN CALL DEBUG;
END;
BINSEM_GETSTATS_ and
BINSEM_STAT_VERSION_ Example
Beginning with the J06.14 and H06.15 RVUs, the BINSEM_GETSTATS_ and
BINSEM_STAT_VERSION_ procedures are available. See the Guardian Procedure
Calls Reference Manual for details of these procedures.
The following binsemc program is an example of using the BINSEM_GETSTATS_
and BINSEM_STAT_VERSION_ procedures. It illustrates how a program can display
statistics about its own use of binary semaphores. Alternatively, the user could invoke
the SEMSTAT utility documented in the TACL Reference Manual.
#include <kbinsem.h> _nolist
#include <cextdecs(PROCESSHANDLE_GETMINE_)> _nolist
#include <stdio.h> _nolist
binSemID_t semID;
short err;
unsigned int ret;
binSemStats_t stat;
NSK_PHandle pHandle;
int main(int argc, char * argv[])