Open System Services Porting Guide (G06.29+, H06.06+, J06.03+)

For additional information about Guardian segments, see the Managing Memory chapter in the
Guardian Programmer’s Guide and the descriptions of SEGMENT_ALLOCATE_,
SEGMENT_ALLOCATE64_, SEGMENT_DEALLOCATE_ and SEGMENT_RESIZE_ in the Guardian
Procedure Calls Reference Manual.
In addition to these techniques that employ existing memory-mapping techniques, there are others
that do not actually map memory.
An alternative approach to mapping the file into memory is to open the file and manipulate its
contents by reading and writing portions of the file to and from buffers. Such usage can be more
portable than using memory mapping, but might be less convenient and sometimes less efficient.
You can combine the malloc() and file approaches: allocate the space, read in the contents of
the file, manipulate the memory, and then (optionally) write the contents back to the file. The FLOSS
library includes an implementation of mmap() and munmap() using this approach. This library
can simplify the effort to port code using mmap(), if that usage fits the restrictions of this approach:
The file is not actually mapped into memory, so the data cannot be shared simultaneously by
multiple processes.
Any modifications to the data are written back to the file only by an explicit munmap()
invocation; if the program terminates without calling munmap(), the changes are lost.
The entire unmapped range is written, not just the pages that have changed, so I/O costs can
be higher if modifications occur sparsely across a large range.
The FLOSS implementation supports only one or two mapped ranges.
The munmap() range must begin at the same address as a currently mapped range; if the
specified length is less than that of the mapping, only that portion is written, but the whole
mapped range is unmapped.
Multiple Threads in Applications
Multithreading is a programming method that enables multiple threads of execution in a process’s
address space. Also, multithreading allows many sequential processing tasks to execute concurrently
within a process (for example, a terminal control process). Multithreaded applications take
advantage of a shared-memory, multiprocessor system.
Guardian and OSS environments do not support multithreading. One way to support multithreaded
applications is to use the user-level multithreading package provided as Standard POSIX Threads
(T1248).
Standard POSIX Threads is a set of services and tools that supports the creation, use, and
maintenance of distributed applications in a heterogeneous computing environment. Standard
POSIX Threads provides interoperability and security among different environments.
An alternative to using multithreaded applications is to redesign your application without using
threads by using the select() function and nonblocking I/O. Usually this redesign involves
changing the logic of your application.
The STREAMS Feature
STREAMS is a programming feature that allows you to insert modules into your communications
stream, providing a uniform mechanism for implementing networking services and other
character-based I/O. The STREAMS interface provides direct access to networking protocol modules
and supports device drivers.
STREAMS is an optional feature of XPG4 and is not supported in the OSS environment. You must
use an alternative feature, such as Guardian sockets, or redesign your program.
UNIX Features Requiring Substitution 87