Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

pthread_getspecific(3)

pthread_keycreate(3)

pthread_setspecific(3)  —  Subroutines

NAME

pthread_setspecific − Sets the per-thread context associated with the specified key for the current thread. 

SYNOPSIS

#include <pthread.h>
int pthread_setspecific(

pthread_key_t key ,
pthread_addr_t value );

PARAMETERS

keyContext key value that uniquely identifies the context value specified in value. This key value must have been obtained from pthread_keycreate, or it must be a key value predefined by the implementation (if predefined key values are provided.) 

valueAddress containing data to be associated with the specified key for the current thread; this is the per-thread context. 

DESCRIPTION

This routine sets the per-thread context associated with the specified key for the current thread. If a context has already been defined for the key in this thread (the current value is not null), the context destructor routine is called to destroy the current value (discussed in pthread_keycreate) and the new value is substituted for it. 

Different threads can bind different values to the same key. These values are typically pointers to blocks of dynamically allocated memory that have been reserved for use by the calling thread. 

RETURN VALUES

If an error condition occurs, this routine returns −1 and sets errno to the corresponding error value.  Possible return values are as follows:

Return Error Description
 0 Successful completion.
−1 [EINVAL] The key value is invalid.

RELATED INFORMATION

pthread_getspecific(3), pthread_keycreate(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026