Home | History | Annotate | Line # | Download | only in libpthread
 $NetBSD: tss.3,v 1.2 2019/04/27 10:57:11 wiz Exp $

Copyright (c) 2016 The NetBSD Foundation, Inc.
All rights reserved.

This code is derived from software contributed to The NetBSD Foundation
by Kamil Rytarowski.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

.Dd October 16, 2016 .Dt TSS 3 .Os .Sh NAME .Nm tss .Nd thread-specific storage functions .Sh LIBRARY .Lb libpthread .Sh SYNOPSIS n threads.h .Vt "typedef" "void" "(*tss_dtor_t)" "(void *)" .Ft int .Fn tss_create "tss_t *key" "tss_dtor_t dtor" .Ft void .Fn tss_delete "tss_t key" .Ft void * .Fn tss_get "tss_t key" .Ft int .Fn tss_set "tss_t key" "void *val" .Vt #define TSS_DTOR_ITERATIONS /* implementation specified */ .Sh DESCRIPTION There are two groups of storage in C programs: l -dash t local storage, t global storage. .El

p Multithreaded programs in C add the third group .Sy thread-specific storage . This data is private to thread and every entry of this type has an associated .Dv tss_t opaque key that is global to all threads in the process. A thread using the .Dv tss_t * pointer accesses private data.

p The .Fn tss_create function creates a thread-specific storage with the .Fa key handler with optional destructor .Fa dtor . If the .Fa dtor parameter is not .Dv NULL , then specified appropriate destructor will be called on thread termination. The destructor is not called if a thread called the .Fn tss_delete function for the specified .Fa key . If, after all the destructors have been called for all

f non- Dv NULL values with associated destructors, there are still some

f non- Dv NULL values with associated destructors, then the process is repeated. If, after at least .Dv TSS_DTOR_ITERATIONS iterations of destructor calls for outstanding

f non- Dv NULL values, there are still some

f non- Dv NULL values with associated destructors, the .Nx implementation stops calling further destructors. The .Xr thrd_exit 3 function must not be called from a destructor.

p The .Fn tss_delete function frees resources used by the thread-specific storage identified by the .Fa key object. This function can be called inside the .Fa dtor destructor, however the destructor is not called by .Fn tss_delete .

p The .Fn tss_get and .Fn tss_set functions are used to get and set thread-specific storage. .Sh RETURN VALUES The .Fn tss_create function returns .Dv thrd_success on success, otherwise .Dv thrd_error on failure.

p The .Fn tss_delete function returns no value.

p The .Fn tss_get returns pointer to thread-specific storage on success or .Dv NULL on failure.

p The .Fn tss_set function returns .Dv thrd_success on success, otherwise .Dv thrd_error on failure. .Sh SEE ALSO .Xr pthread_getspecific 3 , .Xr pthread_key_create 3 , .Xr threads 3 .Sh STANDARDS The .Nm interface conforms to .St -isoC-2011 . .Sh HISTORY This interface first appeared in .Nx 9 . .Sh AUTHORS .An Kamil Rytarowski Aq Mt kamil (at] NetBSD.org