---
name: "pthread_once"
section: "3thr"
platform: "linux"
package: "glibc-doc"
version: "2.1.3-20"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/pthread_once/3thr"
---

# pthread\_once(3thr)

once-only initialization

## NAME

pthread\_once - once-only initialization

## SYNOPSIS

**#include \<pthread.h\>**

**pthread\_once\_t** *once\_control* **= PTHREAD\_ONCE\_INIT;**

**int pthread\_once(pthread\_once\_t \****once\_control***, void (\****init\_routine***) (void));**

## DESCRIPTION

The purpose of  **pthread\_once** is to ensure that a piece of initialization code is executed at most once. The  *once\_control* argument points to a static or extern variable statically initialized to  **PTHREAD\_ONCE\_INIT**.

The first time  **pthread\_once** is called with a given  *once\_control* argument, it calls  *init\_routine* with no argument and changes the value of the  *once\_control* variable to record that initialization has been performed. Subsequent calls to  **pthread\_once** with the same **once\_control** argument do nothing.

## RETURN VALUE

**pthread\_once** always returns 0.

## ERRORS

None.

## AUTHOR

Xavier Leroy \<Xavier.Leroy@inria.fr\>
