#include <pd/chPd.h>int ptdKeyCreate(PdKey *pkey, KnPdHdl destructor);
ptdKeyCreate creates a thread-specific data key visible to all threads in the actor.
The created key is returned in *pkey.
Keys provided by ptdKeyCreate are opaque indices used to locate thread-specific data. Although the same key may be used by different threads, the values bound to the key by ptdSet (2K) are maintained on a per-thread basis, and persist through the life of the calling thread.
Upon key creation, the value NULL shall be associated with the new key in all active threads. Upon thread creation, the value NULL shall be associated will all defined keys in the new thread.
An optional destructor function destructor may be associated with each key. At thread exit, if a key has a non-NULL destructor pointer, and the thread has a non-NULL value associated with that key, the function that is pointed to is called with the current value as its sole argument. The order of destructor calls is unspecified if more than one destructor exists for a thread when it exits.
Destructor calls are repeated at as most PD_DESTRUCTOR_ITERATIONS (as defined in pd/chPd.h) times as necessary to reclaim all thread-specific data, in the case a destructor causes more thread-specific data to be created.
destructor will be called by ptdThreadDelete(2K) in user mode or by the Private Data Manager at thread termination in supervisor mode. Calling ptdThreadDelete(2K) in supervisor mode is useless (and harmless), since it is defined as an empty function.
Upon successful completion, the newly created key is stored in *pkey, and a value of 0 is returned. Otherwise, a positive error code is returned.
The system-imposed limit on the total number of keys per actor has been exceeded (see PTD_KEYS_MAX in pd/chPd.h).
Insufficient memory exists to create the key.
The Private Data Manager is unreachable.
See attributes(5) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|