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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       pthread_key_delete - thread-specific data key deletion
13

SYNOPSIS

15       #include <pthread.h>
16
17       int pthread_key_delete(pthread_key_t key);
18
19

DESCRIPTION

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

RETURN VALUE

37       If  successful,  the  pthread_key_delete()  function shall return zero;
38       otherwise, an error number shall be returned to indicate the error.
39

ERRORS

41       The pthread_key_delete() function may fail if:
42
43       EINVAL The key value is invalid.
44
45
46       The pthread_key_delete() function shall not return  an  error  code  of
47       [EINTR].
48
49       The following sections are informative.
50

EXAMPLES

52       None.
53

APPLICATION USAGE

55       None.
56

RATIONALE

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

FUTURE DIRECTIONS

100       None.
101

SEE ALSO

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