1pthread_getspecific(3C)  Standard C Library Functions  pthread_getspecific(3C)
2
3
4

NAME

6       pthread_getspecific, pthread_setspecific - manage thread-specific data
7

SYNOPSIS

9       cc -mt [ flag... ] file... -lpthread [ library... ]
10       #include <pthread.h>
11
12       int pthread_setspecific(pthread_key_t key, const void *value);
13
14
15       void *pthread_getspecific(pthread_key_t key);
16
17

DESCRIPTION

19       The  pthread_setspecific()  function associates a thread-specific value
20       with a key obtained by way of a previous call to  pthread_key_create().
21       Different threads may bind different values to the same key. These val‐
22       ues are typically pointers to blocks of  dynamically  allocated  memory
23       that have been reserved for use by the calling thread.
24
25
26       The pthread_getspecific() function returns the value currently bound to
27       the specified key on behalf of the calling thread.
28
29
30       The effect of calling  pthread_setspecific()  or  pthread_getspecific()
31       with  a  key  value not obtained from pthread_key_create() or after key
32       has been deleted with pthread_key_delete() is undefined.
33
34
35       Both pthread_setspecific() and pthread_getspecific() may be called from
36       a   thread-specific   data   destructor   function.   However,  calling
37       pthread_setspecific() from a destructor may result in lost  storage  or
38       infinite loops.
39

RETURN VALUES

41       The   pthread_getspecific()  function  returns the thread-specific data
42       value associated with the given key. If no thread-specific  data  value
43       is associated with key, then the value NULL is returned.
44
45
46       Upon  successful completion, the pthread_setspecific() function returns
47       0. Otherwise, an error number is returned to indicate the error.
48

ERRORS

50       The  pthread_setspecific() function will fail if:
51
52       ENOMEM    Insufficient memory exists to associate the  value  with  the
53                 key.
54
55
56
57       The pthread_setspecific() function may fail if:
58
59       EINVAL    The key value is invalid.
60
61
62
63       The  pthread_getspecific() function does not  return errors.
64

ATTRIBUTES

66       See attributes(5) for descriptions of the following attributes:
67
68
69
70
71       ┌─────────────────────────────┬─────────────────────────────┐
72       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
73       ├─────────────────────────────┼─────────────────────────────┤
74       │Interface Stability          │Standard                     │
75       ├─────────────────────────────┼─────────────────────────────┤
76       │MT-Level                     │MT-Safe                      │
77       └─────────────────────────────┴─────────────────────────────┘
78

SEE ALSO

80       pthread_key_create(3C), attributes(5), standards(5)
81
82
83
84SunOS 5.11                        23 Mar 2005          pthread_getspecific(3C)
Impressum