Document revision date: 19 July 1999
[Compaq] [Go to the documentation home page] [How to order documentation] [Help on this site] [How to contact us]
[OpenVMS documentation]

Guide to DECthreads


Previous Contents Index


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 multithreaded application based on DECthreads. 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 multithreaded application based on DECthreads. 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.

Use the DECthreads global mutex when calling a library package that is not designed to run in a multithreaded environment. Unless the documentation for a library function specifically states that it is thread safe, assume that it is not compatible; in other words, assume it is nonreentrant.

The global mutex is one lock. Any code that calls any function that is not known to be reentrant uses the same lock. This prevents problems resulting from dependencies among threads that call library functions and those functions' calling other functions, and so on.

The global mutex is a recursive mutex. A thread that has locked the global mutex can relock it without deadlocking. The locking thread must call pthread_unlock_global_np() as many times as it called this routine, to allow another thread to lock the global mutex.

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.

Associated Routines


Previous Next Contents Index

  [Go to the documentation home page] [How to order documentation] [Help on this site] [How to contact us]  
  privacy and legal statement  
6101PRO_020.HTML