[#BloombergLP-bslmt-ThreadUtil-createKey] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::xref:BloombergLP/bslmt/ThreadUtil.adoc[ThreadUtil]::createKey :relfileprefix: ../../../ :mrdocs: Create a process‐wide key for thread‐local storage. == Synopsis Declared in `<bslmt_threadutil.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- static int createKey( xref:BloombergLP/bslmt/ThreadUtil/Key.adoc[Key]* key, xref:BloombergLP/bslmt/ThreadUtil/Destructor.adoc[Destructor] threadKeyCleanupFunction); ---- == Description Load into the specified `key` a new process‐wide identifier that can be used to store (via `setSpecific`) and retrieve (via `getSpecific`) a pointer value local to each thread, and associate with the new key the specified `threadKeyCleanupFunction`, which will be called by each thread, if `threadKeyCleanupFunction` is non‐zero and the value associated with `key` for that thread is non‐zero, with the associated value as an argument, after the function passed to `create` has returned and before the thread terminates. Return 0 on success, and a non‐zero value otherwise. Note that multiple keys can be defined, which can result in multiple thread key cleanup functions being called for a given thread. == Return Value 0 on success, and a non‐zero value otherwise == Parameters [cols="1,4"] |=== | Name| Description | *key* | receives the new process‐wide thread‐local key | *threadKeyCleanupFunction* | optional destructor for key values |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#