Open System Services Programmer's Guide
12 Using the Standard POSIX Threads Library
Standard POSIX Threads is a user-space implementation of IEEE POSIX Standard 1003.1c pthreads
for use by native C and C++ applications in the OSS environment on NonStop servers. The POSIX
threads standard is officially described in International Standard ISO/IEC 9945-1; 1996 (E) IEEE
Std 1003.1,1996 (Incorporating ANSI/IEEE Stds 1003.1-1990, 1003.1b-1993, 1003.1c-1995,
and 1003.1i-1995). For simplicity, this chapter refers to the “Standard document.” The Standard
document is available for purchase online at http://standards.ieee.org/.
To use threads, you should be familiar with programming in the OSS environment and with writing
threaded applications. See “About This Document” (page 15) for a list of books on programming
with threads. See the Open System Services Porting Guide for information about porting existing
threaded applications and for differences between the previous standard and Standard POSIX
Threads.
• “Standard POSIX Threads” (page 313)
• “Threading Considerations” (page 328)
• “Single Versus Multiple Application Threads” (page 331)
• “Jacket Routines” (page 333)
“SERVERCLASS_SEND and SERVERCLASS_SENDL Jacket Routines” (page 333)◦
◦ “TMF Transaction Jacket Routines” (page 334)
• “Reference Pages for Thread Functions” (page 335)
• “Threaded Application Examples” (page 335)
• “Thread-Aware and Nonblocking OSS Functions” (page 340)
• “Reentrant OSS Functions” (page 365)
• “Thread-Aware Toolkit Functions and Types” (page 368)◦
◦ “Thread-Aware $RECEIVE I/O Functions” (page 372)
• “Thread-Aware Enscribe Functions” (page 376)
• “OSS File Descriptor and Timer Callbacks” (page 379)
Standard POSIX Threads
Threads are scheduled for execution by the Standard POSIX Threads library, not by the NonStop
operating system. All threads created within a process share the same process address space.
With Standard POSIX Threads, one thread can never be preempted by another thread. You must
ensure that threads relinquish control either by explicitly calling the sched_yield() function or
by waiting on a mutex or condition variable.
All resources of a process—for example, open files or memory—are either global or private, as
shown in Table 54. Private resources can be accessed only by a specific thread. Global resources
can be accessed by all threads. Access to global resources by threads should be synchronized
using mutex or condition variables.
Table 54 Process Resources
DescriptionTypeResource
The memory where all thread-local variables are storedPrivateThread stack
The address of the instruction that the thread is about to executePrivateThread program counter
Standard POSIX Threads 313