Open System Services Programmer's Guide

Jacket Routines for Functions Related to Pathway or TMF
The PUT Model library does provide jacket routines for calls to Pathway servers
(SERVERCLASS_SEND and SERVERCLASS_SEND_INFO) and for TMF transactions, as described
in “Jacket Routines (Nonblocking Versions of SERVERCLASS_ and TMF System Calls)” (page 418).
Asynchronous Cancels are Possible
The PUT Model library supports the asynchronous receipt of cancel requests; a thread can exit
from a standard library due to cancellation (see “Thread Safety” (page 406)). Therefore, if you want
to prevent cancellation, you must disable cancellation before making calls to library functions that
contain cancellation points or potential cancellation points.
Beware of Pointers to Static Library Data
Functions that are not thread-aware might return pointers to static data. In this case, one thread
could invalidate another thread’s pointer. For example, in an application that uses the PUT Model
library, the getenv() function returns a pointer to environmental information contained in a static
variable in the library. The content of this variable can be changed by any thread.
When using functions that return pointers to static library data, immediately copy the data to
thread-private memory.
Most of the standard library functions follow the POSIX standard to protect thread safety when PUT
library is used. For more information about thread safety, see “Thread Safety” (page 406).
Beware of Libraries That Maintain Context Across Calls
Most of the standard library functions maintain thread-specific data and context when you use the
PUT Model library. For more information about thread safety, see “Thread Safety” (page 406).
For non-thread-safe standard library functions, you can use a mutex to protect implicit context
maintained by a standard library, for example by bracketing a series of library calls with the lock
and unlock of a mutex. This technique should be used only for short periods of time.
Standard libraries that use an explicit handle to identify the intended context on each call can be
used without interference between threads. File operations that use file descriptors follow this model.
Some libraries allow multiple contexts but do not support explicit context identification on all calls.
Instead, the library allows the caller to establish a current context for the process. With these
libraries, the application is responsible for ensuring that the correct context is made current while
a thread is executing. For example, the TMF transaction-demarcation jacket routines use this method,
relying on an implicit current transaction for the process.
Addressing the Thread Stack
Memory for function variables that are not declared static is allocated from the thread-private stack.
This memory is addressable only while the thread is executing. It is not addressable by other
threads; attempting to read or write variables located in another thread’s stack causes unpredictable
results.
All program data that is to be shared by multiple threads must be external data, static internal
data, or data allocated from the heap. This data should be protected by a mutex, as appropriate.
The Standard provides a set of functions to manage thread-specific data. One use of these functions
is to maintain thread global data, such as state. The interface allows you to declare destructor
functions that are invoked at thread run-down. These functions are distinct from cancellation clean-up
handlers.
The PUT Model library uses a protected stack for signals (see “Signals and Signal Handling
(page 385)).
Threaded Application Programming 429