18.104.22.168 Optionally Implemented POSIX.1 Routines
In this version of the Threads Library, the pthread
interface does not support the following features that are specified in
the POSIX.1 standard:
The POSIX.1 standard directs the Threads Library to provide the macros named _POSIX_THREAD_PROCESS_SHARED , _POSIX_THREAD_PRIO_PROTECT , and _POSIX_THREAD_PRIO_INHERIT to report whether optionally implemented routines are present.
The Threads Library does provide the following macros specified in the POSIX.1 standard:
_POSIX_THREADS : threads are supported
_POSIX_THREAD_SAFE_FUNCTIONS : thread-safe libraries are supported
_POSIX_THREAD_ATTR_STACKSIZE : can specify stack size
_POSIX_THREAD_ATTR_STACKADDR : can specify stack address
_POSIX_THREAD_PRIORITY_SCHEDULING : real-time scheduling control is supported
_POSIX_THREAD_PROCESS_SHARED : cross-process synchronization is supported (Tru64 UNIX only)
The HP proprietary tis interface offers a set of thread-independent services. Use these routines to build software that performs processing that requires synchronization, but without requiring the use of pthreads. That is, use tis routines to build thread-safe code libraries whose routines can be called from either a single-threaded or a multithreaded environment.
In the absence of threads, tis routines impose minimal overhead on the calling program. For instance, tis routines avoid the use of interlocked instructions and memory barriers.
When threads are present, tis routines provide full support for synchronization. Note that there are no tis routines for creating threads or thread objects, because these routines would have no meaning if called from a single-threaded environment.
The tis routines can be classified into these functional categories:
Unlike the other tis interfaces, the read-write lock functions work on a data type different from that used by the pthread read-write lock functions.
Table 1-2 summarizes these groups of tis routines.
|tis_once()||Calls an initialization routine to be executed only once|
|tis_self()||Obtains the identifier of the calling thread|
|tis_yield()||Notifies the scheduler that the calling thread is willing to release its processor to other threads of the same or higher priority|
|Thread Cancelation Routines|
|tis_setcancelstate()||Sets the calling thread's cancelability state to enable or disable the delivery of cancelation requests|
|tis_testcancel()||Requests delivery of any pending cancelation request to the calling thread|
|Thread-Specific Data Key Routines|
|tis_getspecific()||Obtains the thread-specific data associated with the specified key for the calling thread|
|tis_key_create()||Generates a unique thread-specific data key|
|tis_key_delete()||Deletes a thread-specific data key|
|tis_setspecific()||Changes the thread-specific data value associated with the specified key for the calling thread|
|tis_lock_global()||Locks the global mutex|
|tis_mutex_destroy()||Destroys the specified mutex object|
|tis_mutex_init()||Initializes a mutex object|
|tis_mutex_lock()||Locks the specified mutex, if unlocked|
|tis_mutex_trylock()||Tries to lock the specified mutex|
|tis_mutex_unlock()||Unlocks the specified mutex when locked by the calling thread|
|tis_unlock_global()||Unlocks the global mutex|
|Condition Variable Routines|
|tis_cond_broadcast()||Wakes all threads currently waiting on the specified condition variable|
|tis_cond_destroy()||Destroys the specified condition variable object|
|tis_cond_init()||Initializes a condition variable object|
|tis_cond_signal()||Wakes at least one thread that is waiting on the specified condition variable|
|tis_cond_timedwait()||Causes a thread to wait a specified period of time for a condition variable to be signaled or broadcast|
|tis_cond_wait()||Causes the calling thread to wait for the specified condition variable to be signaled or broadcast|
|tis_get_expiration()||Calculates a timeout for a timed condition variable wait|
|OpenVMS I/O Completion Routines|
|tis_io_complete()||Completion AST service routine|
|tis_sync()||Thread-synchronous replacement for $SYNC system service|
|Read-Write Lock Routines|
|tis_read_lock()||Acquires the specified read-write lock for read access|
|tis_read_trylock()||Acquires the specified read-write lock for read access; returns immediately if already locked|
|tis_read_unlock()||Unlocks the specified read-write lock already acquired for read access by the calling thread|
|tis_rwlock_destroy()||Destroys the specified read-write lock object|
|tis_rwlock_init()||Initializes the specified read-write lock object|
|tis_write_lock()||Acquires the specified read-write lock for write access|
|tis_write_trylock()||Acquires the specified read-write lock for write access; returns immediately if already locked|
|tis_write_unlock()||Unlocks the specified read-write lock already acquired for write access by the calling thread|
Previous versions of the Threads Library offered interfaces that under
this version are no longer documented.
22.214.171.124 The cma Interface
This version of the Threads Library supports the HP proprietary CMA (or cma) interface. The cma interface reports errors by raising exceptions. This interface is layered on top of the pthread interface. This interface is usually available only on HP or Compaq platforms.
HP will continue to support existing applications that were developed using the cma interface. Binary compatibility will be supported indefinitely. Nonetheless, HP recommends that, as soon as possible, you migrate any cma code in your existing applications to the latest pthread interface, to take advantage of its standard features, portability, and future enhancements.
Routines of the cma interface are not documented in
126.96.36.199 The d4 (DCEthread) Interfaces
These obsolete interfaces will be removed in a future POSIX Threads release. As of that release, both source and binary code using the d4 (DCEthread) interfaces will no longer compile or execute.
For backward compatibility only, this version of the Threads Library retains full binary support for the d4 interfaces. These interfaces are implementations of the IEEE POSIX 1003.4a/Draft 4 document, and are also known as "DCE threads".
These interfaces include both a "standard" interface that reports errors by setting errno and returning a value of -1, and an "exception-returning" interface that, like the cma interface, reports errors by raising exceptions.
The d4 interfaces will not be provided in a future release of the Threads Library. HP recommends that you migrate any d4 code in your existing applications to the latest pthread interface, to take advantage of its standard features, portability, and future enhancements.
Routines of the d4 interfaces are not documented in this guide. In this guide see Appendix D for information to help you migrate your d4-based programs and applications to the latest pthread interface.
This chapter describes operations that act upon the objects supported
in the pthread interface.
2.1 Threads and Synchronization Objects
A multithreaded program typically manipulates these objects:
When your program creates a thread, mutex, read-write lock or condition variable, it can accept the default attributes for that object or specify an existing attributes object (previously created by your program) that contains particular attribute values. You can also change some of the attributes of a thread after it has begun execution---for example, you can change the thread's priority. However, other attributes, such as stack size, are fixed at execution.
To initialize an attributes object, you can use one of the following routines, depending on the type of object to which the attributes apply:
These routines initialize an attributes object with default values for the individual attributes. To modify any attribute values in an attributes object, use one of the " attr_set " routines, such as pthread_attr_setinheritsched() , described in later sections.
Initializing an attributes object (or changing the values in an attributes object) does not affect the attributes of existing threads, mutexes, read-write locks and condition variables.
To destroy an attributes object, use one of the following routines:
Deleting an attributes object does not affect the attributes of objects
previously created with that attributes object.
2.3 Thread Operations
The following sections describe these operations on threads:
Your program creates a thread using the pthread_create() routine. This routine creates a thread based on the settings of the thread attributes object if specified, which your program must have previously initialized. If called without a specified thread attributes object, pthread_create creates a new thread that has the default attributes.
The Threads Library creates a thread in the ready state and prepares the thread to begin executing its start routine, the function passed to the pthread_create() routine. Depending on the presence of other threads and their scheduling attributes, the new thread might preempt its creator (that is, it might start before the call to pthread_create() returns). The caller of pthread_create() can synchronize with the new thread using any mutually agreed upon mechanism or await its termination using pthread_join() .
The Threads Library assigns each new thread a thread identifier, which is written into the address specified as the pthread_create() routine's thread argument. The new thread's identifier is written before the new thread executes.
You can create a thread that is detached. To do so, create a thread using a thread attributes object whose detachstate attribute has been set, using the pthread_attr_setdetachstate() routine, to PTHREAD_CREATE_DETACHED . This is useful for creating a thread that your program knows will not be joined by any other thread. That is, when such a thread terminates, the thread and its thread object are automatically destroyed.
For more detailed information about thread creation, see the reference
description of the
routine in Part 2.
2.3.2 Setting the Attributes of a New Thread
When creating a thread, your program can optionally specify the attributes of the new thread using a thread attributes object. To do so, your program must:
After your program creates a thread attributes object, it can be reused for each new thread that the program creates. For the details about creating and deleting a thread attributes object, see the descriptions in Part 2 of the pthread_attr_init() and pthread_attr_destroy() routines.
Using the thread attributes object, your program can specify these attributes of a new thread:
By default, a new thread is created with the scheduling attributes
(policy, parameters and contention scope) of its creator. If an
attributes object is specified, the scheduling attribute values are
ignored. When you want to create a thread with different scheduling
attributes, you must set the attribute values, and also set the value
of the inheritsched attribute to
. You do this by calling the
routine. The default value is
188.8.131.52 Setting the Scheduling Policy Attribute
The scheduling policy attribute describes how new threads are scheduled for execution relative to the other threads in the process.
A thread has one of the following scheduling policies:
Section 2.3.6 describes and shows the effect of the scheduling policy on thread scheduling.