Guide to DECthreads


Previous | Contents

int
pthread_getschedparam (
pthread_t thread,
int *policy,
struct sched_param *param);


ARGUMENTS

thread

Thread whose scheduling policy and parameters are obtained.

policy

Receives the value of the scheduling policy for the thread specified in thread. Refer to the description of the pthread_setschedparam() routine for valid parameters and their values.

param

Receives the value of the scheduling parameters for the thread specified in thread. Refer to the description of the pthread_setschedparam() routine for valid values.

DESCRIPTION

This routine obtains both the current scheduling policy and associated scheduling parameters of the thread specified by the thread argument.

The priority value returned in the param structure is the value specified in the attr argument passed to pthread_create() or by the most recent call to pthread_setschedparam() that affects the target thread.

This routine differs from pthread_attr_getschedpolicy() and
pthread_attr_getschedparam(), in that those routines get the scheduling policy and parameter attributes that are used to establish the priority and scheduling policy of a new thread when it is created. This routine, however, obtains the scheduling policy and parameters of an existing thread.

Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return Description
0 Successful completion.
[ESRCH] The value specified by thread does not refer to an existing thread.

Associated Routines


pthread_getsequence_np

Obtains the unique identifier for the specified thread.

Syntax

pthread_getsequence_np(
thread );

Argument Data Type Access
thread opaque pthread_t read
C Binding #include <pthread.h>

unsigned long
pthread_getsequence_np (
pthread_t thread);


ARGUMENTS

thread

Thread whose sequence number is to be obtained.

DESCRIPTION

This routine obtains and returns the DECthreads thread sequence number for the thread identified by the thread object specified in the thread argument.

The thread sequence number provides a unique identifier for each existing thread. A thread's thread sequence number is never reused while the thread exists, but can be reused after the thread terminates. The debugger interfaces use this sequence number to identify each thread in commands and in display output.

The result of calling this routine is undefined if the thread argument does not specify a valid thread object.

Return Values No errors are returned. This routine returns the DECthreads thread sequence number for the thread identified by the thread object specified in the thread argument. The result of calling this routine is undefined if the thread argument does not specify a valid thread.

Associated Routines


pthread_getspecific

Obtains the thread-specific data associated with the specified key.

Syntax

pthread_getspecific(
key );

Argument Data Type Access
key opaque pthread_key_t read
C Binding #include <pthread.h>

void
*pthread_getspecific (
pthread_key_t key);


ARGUMENTS

key

The context key identifies the thread-specific data to be obtained. Obtain this key by calling the pthread_key_create() routine.

DESCRIPTION

This routine obtains the thread-specific data associated with the specified key for the current thread. This routine returns the value currently bound to the specified key on behalf of the calling thread.

This routine may be called from a thread-specific data destructor function.

Return Values No errors are returned. This routine returns the thread-specific data value associated with the specified key argument. If no thread-specific data value is associated with key, or if key is not defined, then this routine returns a NULL value.

Associated Routines


pthread_get_expiration_np

Obtains a value representing a desired expiration time.

Syntax

pthread_get_expiration_np(
delta ,
abstime );

Argument Data Type Access
delta struct timespec read
abstime struct timespec write
C Binding #include <pthread.h>

int
pthread_get_expiration_np (
const struct timespec *delta,
struct timespec *abstime);


ARGUMENTS

delta

Number of seconds and nanoseconds to add to the current system time. (The result is the time in the future.) This result will be placed in abstime.

abstime

Value representing the absolute expiration time. The absolute expiration time is obtained by adding delta to the current system time. The resulting abstime is in Universal Coordinated Time (UTC). This value should be passed to the pthread_cond_timedwait() routine.

DESCRIPTION

This routine adds a specified interval to the current absolute system time and returns a new absolute time. This new absolute time is used as the expiration time in a call to pthread_cond_timedwait().

The timespec structure contains the following two fields:

Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return Description
0 Successful completion.
[EINVAL] The value specified by delta is invalid.

Associated Routines


pthread_join


pthread_join32(), pthread_join64()

The pthread_join32() and pthread_join64() forms are only valid in 64-pointer environments for OpenVMS Alpha. For information regarding 32- and 64-bit pointers, see Appendix B. Ensure that your compiler provides 64-bit support prior to using pthread_join64().

Causes the calling thread to wait for the termination of a specified thread.


Syntax

pthread_join(
thread ,
value _ptr );

Argument Data Type Access
thread opaque pthread_t read
value_ptr void * write
C Binding #include <pthread.h>

int
pthread_join (
pthread_t thread,
void **value_ptr);


ARGUMENTS

thread

Thread whose termination is awaited by the calling routine.

value_ptr

Return value of the terminating thread (when that thread either calls pthread_exit() or returns.)

DESCRIPTION

This routine suspends execution of the calling thread until the specified target thread thread terminates.

On return from a successful pthread_join() call with a non-NULL value_ptr argument, the value passed to pthread_exit() is returned in the location referenced by value_ptr, and the terminating thread is detached.

If more than one thread attempts to join with the same thread, the results are unpredictable.

A call to pthread_join() returns after the target thread terminates. The pthread_join() routine is a deferred cancelation point: the target thread will not be detached if the thread blocked in pthread_join() is canceled.

If a thread calls this routine and specifies its own pthread_t, a deadlock can result.

The pthread_join() (or pthread_detach()) routine should eventually be called for every thread that is created with the detachstate attribute of its thread object set to PTHREAD_CREATE_JOINABLE, so that storage associated with the thread can be reclaimed.

For OpenVMS Alpha systems only, you can call pthread_join32() or pthread_join64() instead of pthread_join(). The pthread_join32() form returns a 32-bit void * value in the address to which value_ptr points. The pthread_join64() form returns a 64-bit void * value. You can call either, or you can call pthread_join(). The pthread_join() routine is defined to pthread_join64() if you compile using /pointer_size=long. If you do not specify /pointer_size, or if you specify /pointer_size=short, then pthread_join() is defined to be pthread_join32(). Note that if you call pthread_join32() and the thread with which you join returns a 64-bit value, the high 32 bits of which are not 0 (zero), DECthreads discards those high bits with no warning.

Return Values If an error condition occurs, this routine returns an integer indicating the type of error. Possible return values are as follows:

Return Description
0 Successful completion.
[EINVAL] The value specified by thread does not refer to a joinable thread.
[ESRCH] The value specified by thread does not refer to an existing thread ID.
[EDEADLK] A deadlock was detected, or thread specifies the calling thread.

Associated Routines


pthread_key_create

Generates a unique thread-specific data key.

Syntax

pthread_key_create(
key ,
destructor );

Argument Data Type Access
key opaque pthread_key_t write
destructor procedure read
C Binding #include <pthread.h>

int
pthread_key_create (
pthread_key_t *key,
void (*destructor)(void *));


ARGUMENTS

key

The new thread-specific data key.

destructor

Procedure called to destroy a thread-specific data value associated with the created key when the thread terminates. Note that the argument to the destructor for the user-specified routine is the non-NULL value associated with a key.

DESCRIPTION

This routine generates a unique, thread-specific data key that is visible to all threads in the process. The variable key provided by this routine is an opaque object used to locate thread-specific data. Although the same key value can be used by different threads, the values bound to the key by pthread_setspecific() are maintained on a per-thread basis and persist for the life of the calling thread.

DECthreads imposes a maximum number of thread-specific data keys, equal to the symbolic constant PTHREAD_KEYS_MAX.

Thread-specific data allows client software to associate "static" information with the current thread. For example, where a routine declares a variable static in a single-threaded program, a multithreaded version of the program might create a thread-specific data key to store the same variable.

This routine generates and returns a new key value. The key reserves a cell within each thread. Each call to this routine creates a new cell that is unique within an application invocation. Keys must be generated from initialization code that is guaranteed to be called only once within each process. (See the pthread_once() description for more information.)

When a thread terminates, its thread-specific data is automatically destroyed; however, the key remains unless destroyed by a call to pthread_key_delete(). An optional destructor function can be associated with each key. At thread exit, if a key has a non-NULL destructor pointer, and the thread has a non-NULL value associated with that key, the destructor function is called with the current associated value as its sole argument. The order in which thread-specific data destructors are called at thread termination is undefined.

Before each destructor is called, the thread's value for the corresponding key is set to NULL. After the destructors have been called for all non-NULL values with associated destructors, if there are still some non-NULL values with associated destructors, then this sequence of actions is repeated. If there are still non-NULL values for any key with a destructor after four repetitions of this sequence, DECthreads terminates the thread. At this point, any key values that represent allocated heap will be lost. Note that this occurs only when a destructor performs some action that creates a new value for some key. Your program's destructor code should attempt to avoid this sort of circularity.

Return Values If an error condition occurs, this routine returns an integer indicating the type of error. Possible return values are as follows:

Return Description
0 Successful completion.
[EAGAIN] The system lacked the necessary resources to create another thread-specific data key, or the limit on the total number of keys per process ( PTHREAD_KEYS_MAX) has been exceeded.
[ENOMEM] Insufficient memory exists to create the key.

Associated Routines


pthread_key_delete

Deletes a thread-specific data key.

Syntax

pthread_key_delete(
key );

Argument Data Type Access
key opaque pthread_key_t write
C Binding #include <pthread.h>

int
pthread_key_delete (
pthread_key_t key);


ARGUMENTS

key

Context key to be deleted.

DESCRIPTION

This routine deletes the thread-specific data key specified by the key argument, which must have been previously returned by pthread_key_create().

The thread-specific data values associated with key need not be NULL at the time this routine is called. The application must free any application storage or perform any cleanup actions for data structures related to the deleted key or associated thread-specific data in any threads. This cleanup can be done either before or after this routine is called.

Do not attempt to use the key after calling this routine; this results in unpredictable behavior.

No destructor functions are invoked by this routine. Any destructor functions that may have been associated with key shall no longer be called upon thread exit. pthread_key_delete() can be called from within destructor functions.

Return Values If an error condition occurs, this routine returns an integer indicating the type of error. Possible return values are as follows:
Return Description
0 Successful completion.
[EINVAL] The key value is an invalid argument.

Associated Routines


pthread_key_getname_np

Obtains the object name from a thread-specific data key object.

Syntax

pthread_key_getname_np(
key ,
name ,
len );

Argument Data Type Access
key opaque pthread_key_t read
name char write
len opaque size_t read
C Binding #include <pthread.h>

int
pthread_key_getname_np (
pthread_key_t *key,
char *name,
size_t len);


ARGUMENTS

key

Address of the thread-specific data key object whose object name is to be obtained.

name

Location to store the obtained object name.

len

Length in bytes of buffer at the location specified by name.

DESCRIPTION

This routine copies the object name from the thread-specific data key object specified by the key argument to the buffer at the location specified by the name argument. Before calling this routine, your program must allocate the buffer indicated by name.

The object name is a C language string and provides an identifier that is meaningful to a person debugging a DECthreads-based multithreaded application. The maximum number of characters in the object name is 31.

If the specified thread-specific data key object has not been previously set with an object name, this routine copies a C language null string into the buffer at location name.

Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return Description
0 Successful completion.
[EINVAL] The value specified by key is invalid.

Associated Routines


pthread_key_setname_np

Changes the object name in a thread-specific data key object.

Syntax

pthread_key_setname_np(
key ,
name ,
mbz );

Argument Data Type Access
key opaque pthread_key_t write
name char read
mbz void read
C Binding #include <pthread.h>

int
pthread_key_setname_np (
pthread_key_t *cond,
const char *name,
void *mbz);


ARGUMENTS

key

Address of the thread-specific data key object whose object name is to be changed.

name

Object name value to copy into the condition variable object.

mbz

(Must be zero) Argument for use by DECthreads.

DESCRIPTION

This routine changes the object name in the thread-specific data key object specified by the key argument to the value specified by the name argument. To set a new thread-specific data key object's object name, call this routine immediately after initializing the key object.

The object name is a C language string and provides an identifier that is meaningful to a person debugging a DECthreads-based multithreaded application. The maximum number of characters in the object name is 31.

Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return Description
0 Successful completion.
[EINVAL] The value specified by key is invalid, or the length in characters of name exceeds 31.
[ENOMEM] Insufficient memory exists to create a copy of the object name string.

Associated Routines


pthread_kill

Delivers a signal to a specified target thread.

This routine is for DIGITAL UNIX systems only.


Syntax

pthread_kill(
thread ,
sig );

Argument Data Type Access
thread opaque pthread_t read
sig integer read
C Binding #include <pthread.h>

int
pthread_kill (
pthread_t thread,
int sig);


ARGUMENTS

thread

Thread to receive a signal request.

sig

A signal request. If sig is zero, error checking is performed, but no signal is sent.

DESCRIPTION

This routine sends a signal to the specified target thread thread. Any signal defined to stop, continue, or terminate will stop or terminate the process, even though it can be handled by the target thread. For example, SIGTERM terminates all threads in the process, even though it can be handled by the target thread.

Specifying a sig argument of 0 (zero) causes this routine to validate the thread argument but not to deliver any signal.

The name of the "kill" routine is sometimes misleading, because many signals do not terminate a thread.

The various signals are as follows:
SIGHUP SIGPIPE SIGTTIN
SIGINT SIGALRM SIGTTOU
SIGQUIT SIGTERM SIGIO
SIGTRAP SIGUSR1 SIGXCPU
SIGABRT SIGSYS SIGXFSZ
SIGEMT SIGURG SIGVTALRM
SIGFPE SIGSTOP SIGPROF
SIGKILL SIGTSTP SIGINFO
SIGBUS SIGCONT SIGUSR1
SIGSEGV SIGCHLD SIGUSR2

If this routine does not execute successfully, no signal is sent.

Return Values If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Return Description
0 Successful completion.
[EINVAL] The value of sig is invalid or an unsupported signal value.
[ESRCH] The value of thread does not specify an existing thread.

pthread_lock_global_np

Locks the DECthreads global mutex if the global mutex is unlocked. If the global mutex is locked by another thread, causes the thread to wait for the global mutex to become available.

Syntax

pthread_lock_global_np( );

C Binding #include <pthread.h>

int
pthread_lock_global_np (void);


ARGUMENTS

None

DESCRIPTION

This routine locks the DECthreads global mutex. If the global mutex is currently held by another thread when a thread calls this routine, the thread waits for the global mutex to become available.

The thread that has locked the global mutex becomes its current owner and remains the owner until the same thread has unlocked it. This routine returns with the global mutex in the locked state and with the current thread as the global mutex's current owner.


Previous | Next | Contents