1PTHREAD_GETSPECIFIC(P)     POSIX Programmer's Manual    PTHREAD_GETSPECIFIC(P)
2
3
4

NAME

6       pthread_getspecific, pthread_setspecific - thread-specific data manage‐
7       ment
8

SYNOPSIS

10       #include <pthread.h>
11
12       void *pthread_getspecific(pthread_key_t key);
13       int pthread_setspecific(pthread_key_t key, const void *value);
14
15

DESCRIPTION

17       The pthread_getspecific() function shall  return  the  value  currently
18       bound to the specified key on behalf of the calling thread.
19
20       The  pthread_setspecific()  function  shall associate a thread-specific
21       value with a key obtained via a previous call to  pthread_key_create().
22       Different threads may bind different values to the same key. These val‐
23       ues are typically pointers to blocks of  dynamically  allocated  memory
24       that have been reserved for use by the calling thread.
25
26       The  effect  of  calling pthread_getspecific() or pthread_setspecific()
27       with a key value not obtained from pthread_key_create()  or  after  key
28       has been deleted with pthread_key_delete() is undefined.
29
30       Both pthread_getspecific() and pthread_setspecific() may be called from
31       a thread-specific data destructor function. A call  to  pthread_getspe‐
32       cific()  for  the thread-specific data key being destroyed shall return
33       the value NULL, unless the  value  is  changed  (after  the  destructor
34       starts)  by  a  call  to pthread_setspecific(). Calling pthread_setspe‐
35       cific() from a  thread-specific  data  destructor  routine  may  result
36       either  in  lost  storage (after at least PTHREAD_DESTRUCTOR_ITERATIONS
37       attempts at destruction) or in an infinite loop.
38
39       Both functions may be implemented as macros.
40

RETURN VALUE

42       The pthread_getspecific() function  shall  return  the  thread-specific
43       data  value  associated  with the given key. If no thread-specific data
44       value is associated with key, then the value NULL shall be returned.
45
46       If successful, the pthread_setspecific() function  shall  return  zero;
47       otherwise, an error number shall be returned to indicate the error.
48

ERRORS

50       No errors are returned from pthread_getspecific().
51
52       The pthread_setspecific() function shall fail if:
53
54       ENOMEM Insufficient memory exists to associate the value with the key.
55
56
57       The pthread_setspecific() function may fail if:
58
59       EINVAL The key value is invalid.
60
61
62       These functions shall not return an error code of [EINTR].
63
64       The following sections are informative.
65

EXAMPLES

67       None.
68

APPLICATION USAGE

70       None.
71

RATIONALE

73       Performance  and  ease-of-use of pthread_getspecific() are critical for
74       functions that rely on maintaining state in thread-specific data. Since
75       no  errors  are required to be detected by it, and since the only error
76       that could be detected is the use of an invalid key,  the  function  to
77       pthread_getspecific()  has  been designed to favor speed and simplicity
78       over error reporting.
79

FUTURE DIRECTIONS

81       None.
82

SEE ALSO

84       pthread_key_create()    ,    the    Base    Definitions    volume    of
85       IEEE Std 1003.1-2001, <pthread.h>
86
88       Portions  of  this text are reprinted and reproduced in electronic form
89       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
90       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
91       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
92       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
93       event of any discrepancy between this version and the original IEEE and
94       The  Open Group Standard, the original IEEE and The Open Group Standard
95       is the referee document. The original Standard can be  obtained  online
96       at http://www.opengroup.org/unix/online.html .
97
98
99
100IEEE/The Open Group                  2003               PTHREAD_GETSPECIFIC(P)
Impressum