Adelsbach Enhanced Threading Library

Manual Pages (DD-00013-001)

Enhanced Threading Library > call_once (3)
HTML TXT PDF PS
call_once(3) Library Functions Manual call_once(3)

call_oncecall function only from a single thread, once

library “threads”
#include <threads.h>

once_flag once = ONCE_FLAG_INIT;


void
call_once(once_flag *flag, void (*fn)());

The () function calls the given callback function fn exactly once even when called from multiple threads at the same time. This is done by setting the given flag atomically upon entry to the function. The flag must be initialized to ONCE_FLAG_INIT before calling call_once().

The call_once() function first appeared in the C11 standard ISO/IEC 9899:2011.

Jan Adelsbach <jan@jadelsbach.de>

Debian