10f7d6847SJulian Elischer.\" Copyright (c) 1996 John Birrell <jb@cimlogic.com.au>. 20f7d6847SJulian Elischer.\" All rights reserved. 30f7d6847SJulian Elischer.\" 40f7d6847SJulian Elischer.\" Redistribution and use in source and binary forms, with or without 50f7d6847SJulian Elischer.\" modification, are permitted provided that the following conditions 60f7d6847SJulian Elischer.\" are met: 70f7d6847SJulian Elischer.\" 1. Redistributions of source code must retain the above copyright 80f7d6847SJulian Elischer.\" notice, this list of conditions and the following disclaimer. 90f7d6847SJulian Elischer.\" 2. Redistributions in binary form must reproduce the above copyright 100f7d6847SJulian Elischer.\" notice, this list of conditions and the following disclaimer in the 110f7d6847SJulian Elischer.\" documentation and/or other materials provided with the distribution. 120f7d6847SJulian Elischer.\" 3. All advertising materials mentioning features or use of this software 130f7d6847SJulian Elischer.\" must display the following acknowledgement: 140f7d6847SJulian Elischer.\" This product includes software developed by John Birrell. 150f7d6847SJulian Elischer.\" 4. Neither the name of the author nor the names of any co-contributors 160f7d6847SJulian Elischer.\" may be used to endorse or promote products derived from this software 170f7d6847SJulian Elischer.\" without specific prior written permission. 180f7d6847SJulian Elischer.\" 190f7d6847SJulian Elischer.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 200f7d6847SJulian Elischer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 210f7d6847SJulian Elischer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 220f7d6847SJulian Elischer.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 230f7d6847SJulian Elischer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 240f7d6847SJulian Elischer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 250f7d6847SJulian Elischer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 260f7d6847SJulian Elischer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 270f7d6847SJulian Elischer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 280f7d6847SJulian Elischer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 290f7d6847SJulian Elischer.\" SUCH DAMAGE. 300f7d6847SJulian Elischer.\" 310f7d6847SJulian Elischer.Dd April 4, 1996 320f7d6847SJulian Elischer.Dt PTHREAD_KEY_CREATE 3 33a307d598SRuslan Ermilov.Os 340f7d6847SJulian Elischer.Sh NAME 350f7d6847SJulian Elischer.Nm pthread_key_create 360f7d6847SJulian Elischer.Nd thread-specific data key creation 37d8a78688SAlexey Zelkin.Sh LIBRARY 38ec7452f1SRuslan Ermilov.Lb libpthread 390f7d6847SJulian Elischer.Sh SYNOPSIS 4032eef9aeSRuslan Ermilov.In pthread.h 410f7d6847SJulian Elischer.Ft int 420f7d6847SJulian Elischer.Fn pthread_key_create "pthread_key_t *key" "void (*destructor)(void *)" 430f7d6847SJulian Elischer.Sh DESCRIPTION 440f7d6847SJulian ElischerThe 450f7d6847SJulian Elischer.Fn pthread_key_create 460f7d6847SJulian Elischerfunction creates a thread-specific data key visible to all threads in the 47c6ff3a1bSSheldon Hearnprocess. 48c6ff3a1bSSheldon HearnKey values provided by 490f7d6847SJulian Elischer.Fn pthread_key_create 50c6ff3a1bSSheldon Hearnare opaque objects used to locate thread-specific data. 51c6ff3a1bSSheldon HearnAlthough the same 520f7d6847SJulian Elischerkey value may be used by different threads, the values bound to the key 530f7d6847SJulian Elischerby 540f7d6847SJulian Elischer.Fn pthread_setspecific 550f7d6847SJulian Elischerare maintained on a per-thread basis and persist for the life of the calling 560f7d6847SJulian Elischerthread. 570f7d6847SJulian Elischer.Pp 580f7d6847SJulian ElischerUpon key creation, the value NULL is associated with the new key in all 59c6ff3a1bSSheldon Hearnactive threads. 60c6ff3a1bSSheldon HearnUpon thread creation, the value NULL is associated with all 610f7d6847SJulian Elischerdefined keys in the new thread. 620f7d6847SJulian Elischer.Pp 63c6ff3a1bSSheldon HearnAn optional destructor function may be associated with each key value. 64c6ff3a1bSSheldon HearnAt 650f7d6847SJulian Elischerthread exit, if a key value has a non-NULL destructor pointer, and the 660f7d6847SJulian Elischerthread has a non-NULL value associated with the key, the function pointed 67c6ff3a1bSSheldon Hearnto is called with the current associated value as its sole argument. 68c6ff3a1bSSheldon HearnThe 690f7d6847SJulian Elischerorder of destructor calls is unspecified if more than one destructor exists 700f7d6847SJulian Elischerfor a thread when it exits. 710f7d6847SJulian Elischer.Pp 720f7d6847SJulian ElischerIf, after all the destructors have been called for all non-NULL values 730f7d6847SJulian Elischerwith associated destructors, there are still some non-NULL values with 74c6ff3a1bSSheldon Hearnassociated destructors, then the process is repeated. 75c6ff3a1bSSheldon HearnIf, after at least 760f7d6847SJulian Elischer[PTHREAD_DESTRUCTOR_ITERATIONS] iterations of destructor calls for 770f7d6847SJulian Elischeroutstanding non-NULL values, there are still some non-NULL values with 780f7d6847SJulian Elischerassociated destructors, the implementation stops calling destructors. 790f7d6847SJulian Elischer.Sh RETURN VALUES 800f7d6847SJulian ElischerIf successful, the 810f7d6847SJulian Elischer.Fn pthread_key_create 820f7d6847SJulian Elischerfunction will store the newly created key value at the location specified by 830f7d6847SJulian Elischer.Fa key 84c6ff3a1bSSheldon Hearnand returns zero. 85c6ff3a1bSSheldon HearnOtherwise an error number will be returned to indicate 860f7d6847SJulian Elischerthe error. 870f7d6847SJulian Elischer.Sh ERRORS 889d09157aSPhilippe CharnierThe 890f7d6847SJulian Elischer.Fn pthread_key_create 909d09157aSPhilippe Charnierfunction will fail if: 910f7d6847SJulian Elischer.Bl -tag -width Er 920f7d6847SJulian Elischer.It Bq Er EAGAIN 930f7d6847SJulian ElischerThe system lacked the necessary resources to create another thread-specific 940f7d6847SJulian Elischerdata key, or the system-imposed limit on the total number of keys per process 950f7d6847SJulian Elischer[PTHREAD_KEYS_MAX] would be exceeded. 960f7d6847SJulian Elischer.It Bq Er ENOMEM 970f7d6847SJulian ElischerInsufficient memory exists to create the key. 980f7d6847SJulian Elischer.El 990f7d6847SJulian Elischer.Sh SEE ALSO 1000f7d6847SJulian Elischer.Xr pthread_getspecific 3 , 10175141cc9SWolfram Schneider.Xr pthread_key_delete 3 , 10275141cc9SWolfram Schneider.Xr pthread_setspecific 3 1030f7d6847SJulian Elischer.Sh STANDARDS 1049d09157aSPhilippe CharnierThe 1050f7d6847SJulian Elischer.Fn pthread_key_create 1069d09157aSPhilippe Charnierfunction conforms to 107096841ecSRuslan Ermilov.St -p1003.1-96 . 108