PTHREAD_BARRIER(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

🌸 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 destroy barrier while it was in use 🚨

The pthread_barrier_destroy() and pthread_barrier_wait() functions may fail if:

  • [EINVAL] β€” the value specified by barrier is invalid πŸ’€

The pthread_barrier_init() function will fail if:

  • [EAGAIN] β€” the system lacks resources, other than memory, to initialize barrier 😭
  • [EINVAL] β€” the count argument is less than 1 🚩
  • [ENOMEM] β€” insufficient memory to initialize barrier 🫠

πŸ¦‹ SEE ALSO πŸ¦‹

pthread_barrierattr(3) πŸ’–


πŸ‘‘ 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