---
name: "pthread_once"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/pthread_once"
---

# pthread\_once(3)

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***, typeof(void (void)) \****init\_routine***;**

## 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.
