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

NAME

6       pthread_key_delete - thread-specific data key deletion
7

SYNOPSIS

9       #include <pthread.h>
10
11       int pthread_key_delete(pthread_key_t key);
12
13

DESCRIPTION

15       The  pthread_key_delete()  function shall delete a thread-specific data
16       key previously returned by  pthread_key_create().  The  thread-specific
17       data  values  associated  with  key  need  not  be  NULL  at  the  time
18       pthread_key_delete() is called.  It is the responsibility of the appli‐
19       cation  to  free any application storage or perform any cleanup actions
20       for data structures related to the deleted key  or  associated  thread-
21       specific data in any threads; this cleanup can be done either before or
22       after pthread_key_delete() is called. Any attempt to use key  following
23       the call to pthread_key_delete() results in undefined behavior.
24
25       The   pthread_key_delete()  function  shall  be  callable  from  within
26       destructor functions. No  destructor  functions  shall  be  invoked  by
27       pthread_key_delete().  Any destructor function that may have been asso‐
28       ciated with key shall no longer be called upon thread exit.
29

RETURN VALUE

31       If successful, the pthread_key_delete()  function  shall  return  zero;
32       otherwise, an error number shall be returned to indicate the error.
33

ERRORS

35       The pthread_key_delete() function may fail if:
36
37       EINVAL The key value is invalid.
38
39
40       The  pthread_key_delete()  function  shall  not return an error code of
41       [EINTR].
42
43       The following sections are informative.
44

EXAMPLES

46       None.
47

APPLICATION USAGE

49       None.
50

RATIONALE

52       A thread-specific data key deletion function has been included in order
53       to  allow  the resources associated with an unused thread-specific data
54       key to be freed. Unused thread-specific  data  keys  can  arise,  among
55       other  scenarios, when a dynamically loaded module that allocated a key
56       is unloaded.
57
58       Conforming applications are  responsible  for  performing  any  cleanup
59       actions  needed  for  data  structures  associated  with  the key to be
60       deleted, including data referenced by thread-specific data values.   No
61       such cleanup is done by pthread_key_delete(). In particular, destructor
62       functions are not called. There are several reasons for  this  division
63       of responsibility:
64
65        1. The  associated  destructor  functions used to free thread-specific
66           data at thread exit time are only guaranteed to work correctly when
67           called  in  the  thread  that  allocated  the thread-specific data.
68           (Destructors themselves may utilize  thread-specific  data.)  Thus,
69           they  cannot  be used to free thread-specific data in other threads
70           at key deletion time. Attempting  to  have  them  called  by  other
71           threads  at  key  deletion  time  would require other threads to be
72           asynchronously interrupted. But since interrupted threads could  be
73           in  an  arbitrary  state, including holding locks necessary for the
74           destructor to run, this approach would fail. In general,  there  is
75           no  safe mechanism whereby an implementation could free thread-spe‐
76           cific data at key deletion time.
77
78        2. Even if there were a means of safely freeing  thread-specific  data
79           associated  with  keys  to  be deleted, doing so would require that
80           implementations be able to enumerate the threads with non-NULL data
81           and  potentially  keep them from creating more thread-specific data
82           while the key deletion is occurring. This special case could  cause
83           extra  synchronization in the normal case, which would otherwise be
84           unnecessary.
85
86       For an application to know that it is safe to delete a key, it  has  to
87       know  that  all  the threads that might potentially ever use the key do
88       not attempt to use it again. For example, it could know this if all the
89       client  threads have called a cleanup procedure declaring that they are
90       through with the module that is being shut down, perhaps by  setting  a
91       reference count to zero.
92

FUTURE DIRECTIONS

94       None.
95

SEE ALSO

97       pthread_key_create()    ,    the    Base    Definitions    volume    of
98       IEEE Std 1003.1-2001, <pthread.h>
99
101       Portions of this text are reprinted and reproduced in  electronic  form
102       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
103       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
104       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
105       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
106       event of any discrepancy between this version and the original IEEE and
107       The Open Group Standard, the original IEEE and The Open Group  Standard
108       is  the  referee document. The original Standard can be obtained online
109       at http://www.opengroup.org/unix/online.html .
110
111
112
113IEEE/The Open Group                  2003                PTHREAD_KEY_DELETE(P)
Impressum