semaphore.h(0P)

🫢 PROLOG 🫢

okay bestie, real talk before we get into it πŸ’… this page is part of the POSIX Programmer's Manual. that's the vibe. but heads up β€” the Linux implementation of this interface may be different (so go check the corresponding Linux manual page for the deets on Linux behavior, fr), or honestly it might not even be implemented on Linux at all. πŸ™ˆ so like, don't come for me if it's not there.


✨ NAME ✨

semaphore.h β€” semaphores πŸŽ€

(and yes bestie, this is the semaphore.h(0P) page, we're in the POSIX Programmer's Manual, iykyk πŸ‘‘)


🌸 SYNOPSIS 🌸

#include <semaphore.h>

πŸ’– DESCRIPTION πŸ’–

so the <semaphore.h> header is gonna define the sem_t type, which is the whole main character of semaphore operations ✨. lowkey important detail: the semaphore may be implemented using a file descriptor, and if that's the case, applications can open up at least a total of {OPEN_MAX} files and semaphores. like, combined. periodt. πŸ’€

The <semaphore.h> header shall define the symbolic constant SEM_FAILED, and it shall have the type sem_t *.

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided. 🫑

int    sem_close(sem_t *);
int    sem_destroy(sem_t *);
int    sem_getvalue(sem_t *restrict, int *restrict);
int    sem_init(sem_t *, int, unsigned);
sem_t *sem_open(const char *, int, ...);
int    sem_post(sem_t *);
int    sem_timedwait(sem_t *restrict, const struct timespec *restrict);
int    sem_trywait(sem_t *);
int    sem_unlink(const char *);
int    sem_wait(sem_t *);

ngl, including the <semaphore.h> header may make symbols defined in the <fcntl.h> and <time.h> headers visible too. so like, surprise guests at the function party πŸŽ‰ not me finding that out the hard way 😭.

The following sections are informative. (aka: the chill sections, not the law sections, bestie 🧚)


πŸ¦‹ APPLICATION USAGE πŸ¦‹

None. πŸ’€ literally nothing. we love a low-effort icon.


πŸ’… RATIONALE πŸ’…

None. again β€” nothing. the silence is the statement. ✨


🌈 FUTURE DIRECTIONS 🌈

None. slay, no notes, we're not going anywhere. πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘

go read these bestie, they're the friend group:

  • <fcntl.h>
  • <sys_types.h>
  • <time.h>

The System Interfaces volume of POSIX.1‐2017, and these absolute icons:

  • sem_close()
  • sem_destroy()
  • sem_getvalue()
  • sem_init()
  • sem_open()
  • sem_post()
  • sem_timedwait()
  • sem_trywait()
  • sem_unlink()

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

🚨 okay so real talk: if there's any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. like, it's the final boss, the actual authority, no cap. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . πŸ›


and that's the whole page bestie!! this one was brought to you by IEEE/The Open Group, dated 2017, on the semaphore.h(0P) page πŸ’– mwah, go forth and semaphore responsibly 🫢✨🌸

πŸ“¦ where this page comes from