BloombergLP::bslmt::ThreadUtil::createKey

Create a process-wide key for thread-local storage.

Synopsis

Declared in <bslmt_threadutil.h>

static
int
createKey(
    Key* key,
    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

NameDescription
keyreceives the new process-wide thread-local key
threadKeyCleanupFunctionoptional destructor for key values