[OpenVMS documentation]
[Site home] [Send comments] [Help with this site] [How to order documentation] [OpenVMS site] [Compaq site]
Updated: 11 December 1998

Guide to DECthreads


Previous Contents Index


sigwait

Suspends a calling thread until a signal arrives.

Syntax

sigwait(
set ,
signal );

Argument Data Type Access
set sigset_t read
signal integer write

C Binding

#include <signal.h>
int
sigwait (
sigset_t *set,
int *signal);

Arguments

set

Set of signals to wait for.

signal

Signal number obtained for the selected signal.

Description

This routine suspends the calling thread until at least one of the signals in the set argument is in the caller's set of pending signals. When this happens, one of those signals is automatically selected and removed from the set of pending signals. The signal number identifying that signal is then returned.

This routine stores the signal number obtained in the address specified in the signal argument.

The effect of calling this routine is unspecified if any signals in the set argument are not blocked at the time of the call.

The set signal set object is created using the set manipulation routines sigemptyset(), sigfillset(), sigaddset(), and sigdelset().

If, while this routine is waiting, a signal occurs that is eligible for delivery (that is, not blocked by the signal mask), that signal is handled asynchronously and the wait is interrupted.

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 the set argument contains an invalid or unsupported signal number.
[EINTR] The wait was interrupted by an unblocked, caught signal.

Associated Routines


Part 3
Compaq Proprietary Interfaces: tis Routines Reference

Part 3 provides detailed descriptions of the Compaq proprietary DECthreads thread-independent services (or tis) interface routines.

These routines are designed to provide efficient tools for thread safety in libraries whose routines do not themselves use threads. The tis interface provides functions identical to several pthread functions. In a program that creates or uses threads, the tis functions provide full thread synchronization and coherence of memory access. But, in a program that does not use threads, the same tis calls provide low-overhead "stub" implementations of pthread features.

The objects created using tis interface routines are the same as pthread interface objects.

The variable errno is not used by the tis routines. Like the pthread routines, the tis routines return integer values indicating the type of error.

Note

In a nonthreaded environment, never code tis routines to use condition variables to block operations. For example, the single-threaded implementation of tis_cond_wait() cannot block. If it did, no other thread would be running to "awaken" the program.

When threads are present, the guidelines for using pthread routines apply to using the corresponding tis routines.


tis_cond_broadcast

Wakes all threads that are waiting on a condition variable.

Syntax

tis_cond_broadcast(
cond );

Argument Data Type Access
cond opaque pthread_cond_t modify

C Binding

#include <tis.h>
int
tis_cond_broadcast (
pthread_cond_t *cond);

Arguments

cond

Address of the condition variable (passed by reference) on which to broadcast.

Description

When threads are not present, this routine performs no actions.

When threads are present, this routine unblocks all threads waiting on the specified condition variable cond.

For further information about actions when threads are present, refer to the pthread_cond_broadcast() description.

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 cond is invalid.

Associated Routines


tis_cond_destroy

Destroys the specified condition variable.

Syntax

tis_cond_destroy(
cond );

Argument Data Type Access
cond opaque pthread_cond_t write

C Binding

#include <tis.h>
int
tis_cond_destroy (
pthread_cond_t *cond);

Arguments

cond

Address of the condition variable (passed by reference) to be destroyed.

Description

This routine destroys the condition variable specified by cond. After this routine is called, DECthreads may reclaim internal storage used by the condition variable object. Call this routine when a condition variable will no longer be referenced.

The results of this routine are unpredictable, if the condition variable specified in cond does not exist or is not initialized.

For more information about actions when threads are present, refer to the pthread_cond_destroy() description.

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 cond is invalid.
[EBUSY] The object being referenced by cond is being referenced by another thread that is currently executing a
tis_cond_wait() on the condition variable specified in cond. (This error can only occur when threads are present.)

Associated Routines


tis_cond_init

Initializes a condition variable.

Syntax

tis_cond_init(
cond );

Argument Data Type Access
cond opaque pthread_cond_t write

C Binding

#include <tis.h>
int
tis_cond_init (
pthread_cond_t *cond);

Arguments

cond

Address of the condition variable (passed by reference) to be initialized.

Description

This routine initializes a condition variable (cond) with the DECthreads default condition variable attributes.

A condition variable is a synchronization object used in conjunction with a mutex. A mutex controls access to shared data. When threads are present, a condition variable allows threads to wait for data to enter a defined state.

For more information about actions taken when threads are present, refer to the pthread_cond_init() description.

Your program can use the macro PTHREAD_COND_INITIALIZER to initialize statically allocated condition variables to the DECthreads default condition variable attributes. Use this macro as follows:
pthread_cond_t condition = PTHREAD_COND_INITIALIZER;

When statically initialized, a condition variable should not also be initialized using tis_cond_init(). Also, a statically initialized condition variable need not be destroyed using tis_cond_destroy().

Return Values

If there is an error condition, the following occurs:
The possible return values are as follows:
Return Description
0 Successful completion.
[EAGAIN] The system lacks the necessary resources to initialize another condition variable, or:

The system-imposed limit on the total number of condition variables under execution by a single user is exceeded.

[EBUSY] The implementation has detected an attempt to reinitialize the object referenced by cond, a previously initialized, but not yet destroyed condition variable.
[EINVAL] The value specified by attr is invalid.
[ENOMEM] Insufficient memory exists to initialize the condition variable.

Associated Routines


tis_cond_signal

Wakes at least one thread that is waiting on the specified condition variable.

Syntax

tis_cond_signal(
cond );

Argument Data Type Access
cond opaque pthread_cond_t modify

C Binding

#include <tis.h>
int
tis_cond_signal (
pthread_cond_t *cond);

Arguments

cond

Address of the condition variable (passed by reference) on which to signal.

Description

When threads are present, this routine unblocks at least one thread that is waiting on the specified condition variable cond.

For more information about actions taken when threads are present, refer to the pthread_cond_signal() description.

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 cond is invalid.

Associated Routines


tis_cond_wait

Causes a thread to wait for the specified condition variable to be signaled or broadcasted.

Syntax

tis_cond_wait(
cond ,
mutex );

Argument Data Type Access
cond opaque pthread_cond_t modify
mutex opaque pthread_mutex_t modify

C Binding

#include <tis.h>
int
tis_cond_wait (
pthread_cond_t *cond,
pthread_mutex_t *mutex);

Arguments

cond

Address of the condition variable (passed by reference) on which to wait.

mutex

Address of the mutex (passed by reference) that is associated with the condition variable specified in cond.

Description

When threads are present, this routine causes a thread to wait for the specified condition variable cond to be signaled or broadcasted.

Calling this routine in a single-threaded environment is a coding error. Because no thread can execute in parallel to issue a call to tis_cond_signal() or tis_cond_broadcast(), using this routine in a single-threaded environment forces the program to exit.

For further information about actions taken when threads are present, refer to the pthread_cond_wait() description.

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 cond or mutex is invalid, or:

Different mutexes are supplied for concurrent
tis_cond_wait() operations on the same condition variable, or:

The mutex was not owned by the calling thread at the time of the call.

Associated Routines


tis_getspecific

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

Syntax

tis_getspecific(
key );

Argument Data Type Access
key opaque pthread_key_t read

C Binding

#include <tis.h>
void *
tis_getspecific (
pthread_key_t key);

Arguments

key

Identifies a value returned by a call to tis_key_create(). This routine returns the data value associated with the thread-specific data key.

Description

This routine returns the value currently bound to the specified thread-specific data key.

This routine can be called from a data destructor function.

When threads are present, the data and keys are thread specific; they enable a library to maintain context on a per-thread basis.

Return Values

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

Associated Routines


tis_key_create

Generates a unique thread-specific data key.

Syntax

tis_key_create(
key ,
destructor );

Argument Data Type Access
key opaque pthread_key_t write
destructor procedure read

C Binding

#include <tis.h>
int
tis_key_create (
pthread_key_t *key,
void (*destructor)(void *));

Arguments

key

Address of a variable that receives the key value. This value is used in calls to tis_getspecific() and tis_setspecific() to get and set the value associated with this key.

destructor

Address of a routine that is called to destroy the context value when a thread terminates with a non-NULL value for the key. Note that this argument is used only when threads are present.

Description

This routine generates a unique thread-specific data key. The key argument points to an opaque object used to locate data.

This routine generates and returns a new key value. The key reserves a cell. 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 tis_once() description for more information.)

Your program can associate an optional destructor function with each key. At thread exit, if a key has a non-NULL destructor function pointer, and the thread has a non-NULL value associated with that key, the function pointed to is called with the current associated value as its sole argument. The order in which data destructors are called at thread termination is undefined.

When threads are present, keys and any corresponding data are thread specific; they enable the context to be maintained on a per-thread basis. For more information about the use of tis_key_create() in a threaded environment, refer to the pthread_key_create() description.

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

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.
[EINVAL] Invalid argument.

Associated Routines


tis_key_delete

Deletes the specified thread-specific data key.

Syntax

tis_key_delete(
key );

Argument Data Type Access
key opaque pthread_key_t write

C Binding

#include <tis.h>
int
tis_key_delete (
pthread_key_t key);

Arguments

key

Thread-specific data key to be deleted.

Description

This routine deletes a thread-specific data key key previously returned by a call to the tis_key_create() routine. The 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 data. This cleanup can be done before or after this routine is called.

Attempting to use the thread-specific data key key after calling this routine results in unpredictable behavior.

No destructor functions are invoked by this routine. Any destructor functions that may have been associated with key will no longer be called upon thread exit.

This routine can be called from 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 value for key is invalid.

Associated Routines


Previous Next Contents Index

[Site home] [Send comments] [Help with this site] [How to order documentation] [OpenVMS site] [Compaq site]
[OpenVMS documentation]

Copyright © Compaq Computer Corporation 1998. All rights reserved.

Legal
6101PRO_026.HTML