Open System Services Porting Guide (G06.24+, H06.03+)

Table Of Contents
OSS Porting Considerations
Open System Services Porting Guide520573-006
6-10
Using Semaphores
In the OSS environment, you usually do not have to be aware of the type of memory a
program is using, unless your programs use Guardian procedures to share memory
with other processes. OSS processes can use OSS functions and Guardian
procedures to share memory with other OSS processes. To share memory with
Guardian processes, OSS processes must use Guardian procedures.
OSS functions allow OSS processes to share flat extended data segments. Guardian
procedures allow processes to share both flat and selected extended data segments.
For more information on managing memory in the OSS environment, refer to the Open
System Services Programmer’s Guide.
Using Semaphores
A semaphore is a counter used to provide access to a shared data object for multiple
processors. Semaphores are an optional feature of the XPG4 specifications. OSS
supports semaphores for single-processor operations, and programs can use either
XPG4 counting or Guardian binary semaphores.
The use of a semaphore synchronizes the access of multiple processes to a shared
resource. Semaphores are created and controlled with the semctl(), semget(), or
semop() function calls. OSS semaphores can be listed and deleted using the ipcs
and ipcrm utilities (refer to the semctl(2), semget(2), and semop(2) reference
pages either online or in the Open System Services System Calls Reference Manual
and to the ipcs(1) and ipcrm(1) reference pages either online or in the Open
System Services Shell and Utilities Reference Manual for more information).
Using the $RECEIVE File
The Guardian $RECEIVE mechanism is an interprocess communication mechanism
that can be used by OSS processes but makes them nonportable. Refer to Using
PROCESS_SPAWN_ on page 6-15, Starting a Guardian Server Process on page 6-26,
$RECEIVE on page 8-18, and to the Open System Services Sockets Programmer’s
Guide for more information.
Memory Model Considerations
For the TNS/R and TNS/E native environments and the G-series TNS environment, the
HP C compiler supports the large-memory model and the 32-bit (or WIDE) data model
for OSS programs. These models support 32-bit pointers and the 32-bit size of type
int. (The HP C compiler does not support the small-memory model or the 16-bit data
model for OSS programs.)
This subsection introduces the memory model and data model for OSS programs and
discusses allocating and deallocating memory when working with OSS programs or
porting applications to OSS environment. Refer to the C/C++ Programmer’s Guide for
details on the memory model in the Guardian environment for native and TNS
environments.