06-06-2002
pthread_key_create, creates a thread-specific data key.
#include<pthread.h>
int pthread_key_create ( key, destructor )
pthread_key_t * key;
void (*destructor) (void *);
- The pthread_key_create creates a thread-specific data key. The key is
shared among all threads within the process, but each thread has specific data
associated with the key. The thread-specific data is a void pointer, initially
set to NULL.
#include <pthread.h>
int pthread_setspecific(pthread_key_t key, const void *value);
- The pthread_setspecific() function associates a thread-specific data value with a key obtained via a previous call to pthread_key_create(). Different threads may bind different values to the same key. These values are typically pointers to blocks of dynamically allocated memory that have been reserved for use by the calling thread.
The effect of calling pthread_setspecific() with a key value not obtained from pthread_key_create() or after the key has been deleted with pthread_key_delete() is undefined.
#include <pthread.h>
int pthread_key_delete(pthread_key_t key);
- The pthread_key_delete() function deletes a thread-specific data key previously returned by pthread_key_create(). The thread-specific data values associated with the key need not be NULL at the time pthread_key_delete() is called. It is the responsibility of the application to free any application storage or perform any cleanup actions for data structures related to the deleted key or associated thread-specific data in any threads; this cleanup can be done either before or after pthread_key_delete(). Any attempt to use the key following the call to pthread_key_delete() results in undefined behavior.
pthread_key_delete() can be called from within destructor functions. No destructor functions are invoked by pthread_key_delete(). Any destructor function that may have been associated with the key is no longer called on thread exit.
#include <pthread.h>
void *pthread_getspecific(pthread_key_t key);
- The pthread_getspecific() function returns the value currently associated with the specified thread-specific data key. The effect of calling pthread_getspecific() with a key value not obtained from pthread_key_create() or after the key has been deleted with pthread_key_delete() is undefined. pthread_getspecific() may be called from a thread-specific data destructor function.
10 More Discussions You Might Find Interesting
1. Programming
Does any one no of some good web site which will explain about how to program using pthreads in a UNIX enviroment? (6 Replies)
Discussion started by: fishman2001
6 Replies
2. Programming
howcome that pthtreads spawn 2 extra processes?
I'm kind of new with pthreads but fork() did not act like this.
Anyone who can give me a technical explanation of what happends with mother / daughter processes?
Best regards Esaia. (2 Replies)
Discussion started by: Esaia
2 Replies
3. Programming
I have created a thread program, it is attached. My problem is that I need to loop this program multiple times, and basically reset everything including the threads created previously. I try to loop the program, the first run is fine, as always, but the second run of the program, the initialize... (0 Replies)
Discussion started by: justgotthis
0 Replies
4. Programming
Hi All,
I ve written a small program to get started off with pthreads. I somehow feel the program doesnt meet the purpose. Please find the code and the output below. Please find my question at the bottom.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void *PrintThread1(void... (4 Replies)
Discussion started by: nhrraj
4 Replies
5. UNIX for Dummies Questions & Answers
How to give superuser privileges while setting the attributes like pthread_attr_setschedpolicy( )??
Even with normal user mode ,it is working fine for me.But in man pages, they have specied that to set the scheduling policy as SCHED_FIFO, the process should have superuser privileges. (0 Replies)
Discussion started by: yashavant.a
0 Replies
6. Programming
I have a doubt .. ( maybe I don't know ..)
Let's say , we got the folowing example ( to understand better what I mean ).
We got two POSIX threads ( pthreads ) , one receives some strings and creates a menu ( for that strings , scrollable menu ) , and another one check's to see if it has to... (2 Replies)
Discussion started by: !_30
2 Replies
7. HP-UX
Hi!
I'm linking my hpux code using -lpthread (gcc), yet it references libpthread_tr.1,
the debug version of the pthread lib. How do I force it to use pthreads?
Thanks, :) (3 Replies)
Discussion started by: zackz
3 Replies
8. Programming
hi
i have a code:
I found that after exiting from child thread memory isn't freed. I commented everything which is "some actions" here, so thread's function contains only two lines. But it doesn't help.
What do I do wrong?
Thanks a lot (3 Replies)
Discussion started by: sery0ga
3 Replies
9. Programming
Situation:
i have multiple pthread_create calls like this:
pthread_create(...., ThreadFunc1,.....);
pthread_create(...., ThreadFunc2,.....);
.
.
which i am using to create multiple threads.All the "ThreadFunc<i>" functions are actually calling same function "Receive" of a class using same... (3 Replies)
Discussion started by: Sastra
3 Replies
10. Programming
Hello,
I am writing a threaded program using the pthread library in linux. I have a master thread that needs to control worker threads, in particular, it has to be able to ensure that none of the worker threads will be running for a specified amount of time, even if the worker threads are... (7 Replies)
Discussion started by: andres625
7 Replies
LEARN ABOUT OSF1
pthread_key_delete
pthread_key_delete(3) Library Functions Manual pthread_key_delete(3)
NAME
pthread_key_delete - Deletes a thread-specific data key.
LIBRARY
DECthreads POSIX 1003.1c Library (libpthread.so)
SYNOPSIS
#include <pthread.h>
int pthread_key_delete(
pthread_key_t key);
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
IEEE Std 1003.1c-1995, POSIX System Application Program Interface
PARAMETERS
Context key to be deleted.
DESCRIPTION
This routine deletes the thread-specific data key specified by the key argument, which must have been previously returned by
pthread_key_create(3).
The thread-specific data values associated with key need not be NULL at the time this routine is called. The application must free any
application storage or perform any cleanup actions for data structures related to the deleted key or associated thread-specific data in any
threads. This cleanup can be done either before or after this routine is called.
Do not attempt to use the key after calling this routine; this results in unpredictable behavior.
No destructor functions are invoked by this routine. Any destructor functions that may have been associated with key shall no longer be
called upon thread exit. pthread_key_delete(3) can be called from within destructor functions.
RETURN VALUES
If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows:
Successful completion. The key value is an invalid argument.
ERRORS
None
RELATED INFORMATION
Functions: pthread_exit(3), pthread_getspecific(3), pthread_key_create(3)
Manuals: Guide to DECthreads and Programmer's Guide
delim off
pthread_key_delete(3)