# semaphore.h - [Overview](#section240345738165629) - [Summary](#section65980240165629) - [Data Structures](#nested-classes) - [Macros](#define-members) - [Functions](#func-members) ## **Overview** **Related Modules:** [IPC](IPC.md) **Description:** Provides functions and structures related to semaphore operations. For example, you can use the functions to create, open, close, and delete semaphores, and perform P and V operations on semaphores. **Since:** 1.0 **Version:** 1.0 ## **Summary** ## Data Structures

Data Structure Name

Description

sem_t

Defines semaphores.

## Macros

Macro Name and Value

Description

SEM_FAILED ((sem_t *)0)

Defines the semaphore failure flag.

## Functions

Function

Description

sem_close (sem_t *sem)

int

Closes a specified semaphore.

sem_destroy (sem_t *sem)

int

Destroys a specified anonymous semaphore that is no longer used.

sem_getvalue (sem_t *__restrict sem, int *__restrict sval)

int

Obtains the count value of a specified semaphore.

sem_init (sem_t *sem, int pshared, unsigned int value)

int

Creates and initializes an anonymous semaphore.

sem_post (sem_t *sem)

int

Increments the semaphore count by 1.

sem_timedwait (sem_t *__restrict sem, const struct timespec *__restrict timeout)

int

Obtains the semaphore, with a timeout period specified.

sem_trywait (sem_t *sem)

int

Attempts to obtain the semaphore.

sem_unlink (const char *name)

int

Deletes a specified semaphore.

sem_wait (sem_t *sem)

int

Obtains the semaphore.