sem_init

Synopsis

#include <semaphore.h>

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

Status

Partially implemented

Conformance

IEEE Std 1003.1-2024

Description

The sem_init() function shall initialise the unnamed semaphore referred to by sem to value, which shall not exceed SEM_VALUE_MAX. The semaphore is usable by any thread of the calling process until it is destroyed with sem_destroy().

A non-zero pshared requests a semaphore shared between processes. Phoenix-RTOS does not implement process-shared unnamed semaphores; use a named semaphore, created with sem_open(), when several processes have to share one.

Initialising a semaphore that is already initialised, or one on which threads are blocked, has undefined results.

Return value

Upon successful completion, sem_init() shall return 0. Otherwise it shall return -1 and set errno to indicate the error.

Errors

This function shall fail if:

  • EINVAL - sem is a null pointer, or value exceeds SEM_VALUE_MAX,

  • ENOSPC - a resource required to initialise the semaphore has been exhausted,

  • ENOSYS - pshared is non-zero; process-shared unnamed semaphores are not supported.

POSIX deviations

No POSIX deviations discovered.