---
name: "PAPI_thread_init"
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_thread_init"
---

# PAPI\_thread\_init(3)

Initialize thread support in the PAPI library.

## NAME

PAPI\_thread\_init - Initialize thread support in the PAPI library.

## SYNOPSIS

## Detailed Description

**Parameters**

*\*id\_fn* Pointer to a function that returns current thread ID.

**PAPI\_thread\_init** initializes thread support in the PAPI library. Applications that make no use of threads do not need to call this routine. This function MUST return a UNIQUE thread ID for every new thread/LWP created. The OpenMP call omp\_get\_thread\_num() violates this rule, as the underlying LWPs may have been killed off by the run-time system or by a call to omp\_set\_num\_threads() . In that case, it may still possible to use omp\_get\_thread\_num() in conjunction with **PAPI\_unregister\_thread()** when the OpenMP thread has finished. However it is much better to use the underlying thread subsystem's call, which is pthread\_self() on Linux platforms.

```
if ( PAPI_thread_init(pthread_self) != PAPI_OK )
    exit(1);
```

**See also**

**PAPI\_register\_thread** **PAPI\_unregister\_thread** **PAPI\_get\_thr\_specific** **PAPI\_set\_thr\_specific** **PAPI\_thread\_id** **PAPI\_list\_threads**

## Author

Generated automatically by Doxygen for PAPI from the source code.
