PTHREAD_BARRIER(3)
πΈ NAME πΈ
bestie, welcome to PTHREAD_BARRIER(3) from the Library Functions Manual π
β this is all about pthread_barrier_destroy, pthread_barrier_init, and pthread_barrier_wait, aka the trio that destroys, initializes, or waits on a barrier object π
π«Ά LIBRARY π«Ά
POSIX Threads Library β that's libpthread, and you link it with -lpthread β¨
β¨ SYNOPSIS β¨
#include <pthread.h>
int
pthread_barrier_destroy(pthread_barrier_t *barrier);
int
pthread_barrier_init(pthread_barrier_t *restrict barrier,
const pthread_barrierattr_t *attr, unsigned count);
int
pthread_barrier_wait(pthread_barrier_t *barrier);
π DESCRIPTION π
okay so pthread_barrier_init() initializes barrier with the attributes specified in attr, or β if attr is NULL β with default attributes π«Ά The number of threads that must call pthread_barrier_wait() before any of the waiting threads can be released is specified by count β¨
pthread_barrier_destroy() destroys barrier and releases any resources that may have been allocated on its behalf π
pthread_barrier_wait() synchronizes calling threads at barrier π
The threads will be blocked from making further progress until a sufficient number of threads calls this function π The number of threads that must call it before any of them will be released is determined by the count argument to pthread_barrier_init() β¨ Once the threads have been released, the barrier will be reset π₯
π§ IMPLEMENTATION NOTES π§
In the 1:1 Threading Library β <pink>libthr</pink>, linked with -lthr β the PTHREAD_BARRIER_SERIAL_THREAD return value will always be returned by the last thread to reach the barrier π
π RETURN VALUES π
If successful, both pthread_barrier_destroy() and pthread_barrier_init() will return zero β¨ Otherwise, an error number will be returned to indicate the error π
If the call to pthread_barrier_wait() is successful, all but one of the threads will return zero π«Ά That one thread will return PTHREAD_BARRIER_SERIAL_THREAD π Otherwise, an error number will be returned to indicate the error π
None of these functions will return EINTR β no cap, not even once π
π ERRORS π
The pthread_barrier_destroy() function will fail if:
[EBUSY]β an attempt was made to destroybarrierwhile it was in use π¨
The pthread_barrier_destroy() and pthread_barrier_wait() functions may fail if:
[EINVAL]β the value specified bybarrieris invalid π
The pthread_barrier_init() function will fail if:
[EAGAIN]β the system lacks resources, other than memory, to initializebarrierπ[EINVAL]β thecountargument is less than 1 π©[ENOMEM]β insufficient memory to initializebarrierπ«
π¦ SEE ALSO π¦
π HISTORY π
The pthread_barrier_destroy(), pthread_barrier_init(), and pthread_barrier_wait() functions first appeared in N:M Threading Library β libkse, linked with -lkse β in FreeBSD 5.2, and in 1:1 Threading Library β libthr, linked with -lthr β in FreeBSD 5.3 π
That's the whole page, bestie β source/version Debian, dated August 17, 2018, and it's the PTHREAD_BARRIER(3) page πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2004 Michael Telahun Makonnen
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms