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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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,  destruc‐
62       tor  functions are not called. There are several reasons for this divi‐
63       sion 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
93       If an implementation detects that the value specified by the key  argu‐
94       ment  to  pthread_key_delete() does not refer to a a key value obtained
95       from pthread_key_create() or refers to a key that has been deleted with
96       pthread_key_delete(),  it  is recommended that the function should fail
97       and report an [EINVAL] error.
98

FUTURE DIRECTIONS

100       None.
101

SEE ALSO

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