---
name: "PAPI_set_thr_specific"
section: "3"
platform: "linux"
package: "libpapi-dev"
version: "7.1.0-5+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/PAPI_set_thr_specific"
---

# PAPI\_set\_thr\_specific(3)

Store a pointer to a thread specific data structure.

## NAME

PAPI\_set\_thr\_specific - Store a pointer to a thread specific data structure.

## SYNOPSIS

## Detailed Description

**Prototype:**

\#include \<**papi.h**\> \
\
  int **PAPI\_set\_thr\_specific( int tag, void \*ptr )**;

**Parameters**

*tag* An identifier, the value of which is either PAPI\_USR1\_TLS or PAPI\_USR2\_TLS. This identifier indicates which of several data structures associated with this thread is to be accessed. \
 *ptr* A pointer to the memory containing the data structure.

**Return values**

*PAPI\_OK* \
 *PAPI\_EINVAL* The *tag* argument is out of range.

In C, **PAPI\_set\_thr\_specific** will save *ptr* into an array indexed by *tag*. There are 2 user available locations and *tag* can be either PAPI\_USR1\_TLS or PAPI\_USR2\_TLS. The array mentioned above is managed by PAPI and allocated to each thread which has called **PAPI\_thread\_init**. There is no Fortran equivalent function.

**Example:**

```
int ret;
RateInfo *state = NULL;
ret = PAPI_thread_init(pthread_self);
if (ret != PAPI_OK) handle_error(ret);
// Do we have the thread specific data setup yet?
ret = PAPI_get_thr_specific(PAPI_USR1_TLS, (void *) &state);
if (ret != PAPI_OK || state == NULL) {
    state = (RateInfo *) malloc(sizeof(RateInfo));
    if (state == NULL) return (PAPI_ESYS);
    memset(state, 0, sizeof(RateInfo));
    state->EventSet = PAPI_NULL;
    ret = PAPI_create_eventset(&state->EventSet);
    if (ret != PAPI_OK) return (PAPI_ESYS);
    ret = PAPI_set_thr_specific(PAPI_USR1_TLS, state);
    if (ret != PAPI_OK) return (ret);
}
```

**See also**

**PAPI\_register\_thread** **PAPI\_thread\_init** **PAPI\_thread\_id** **PAPI\_get\_thr\_specific**

## Author

Generated automatically by Doxygen for PAPI from the source code.
