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
11

NAME

13       pthread_key_delete — thread-specific data key deletion
14

SYNOPSIS

16       #include <pthread.h>
17
18       int pthread_key_delete(pthread_key_t key);
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 shall not return  an  error  code  of
42       [EINTR].
43
44       The following sections are informative.
45

EXAMPLES

47       None.
48

APPLICATION USAGE

50       None.
51

RATIONALE

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

FUTURE DIRECTIONS

101       None.
102

SEE ALSO

104       pthread_key_create()
105
106       The Base Definitions volume of POSIX.1‐2008, <pthread.h>
107
109       Portions of this text are reprinted and reproduced in  electronic  form
110       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
111       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
112       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
113       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
114       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
115       event of any discrepancy between this version and the original IEEE and
116       The  Open Group Standard, the original IEEE and The Open Group Standard
117       is the referee document. The original Standard can be  obtained  online
118       at http://www.unix.org/online.html .
119
120       Any  typographical  or  formatting  errors that appear in this page are
121       most likely to have been introduced during the conversion of the source
122       files  to  man page format. To report such errors, see https://www.ker
123       nel.org/doc/man-pages/reporting_bugs.html .
124
125
126
127IEEE/The Open Group                  2013               PTHREAD_KEY_DELETE(3P)
Impressum