## NAME

sem_init - initialize an unnamed semaphore

## SYNOPSIS

#include <semaphore.h>

int sem_init(sem_t *sem , int pshared , unsigned int value );
typedef struct {
  ...
} sem_t; /*opaque POSIX semaphore*/

## DESCRIPTION

sem_init() is used to initialize the unnamed semaphore, referred to by sem, to value. This semaphore may be used in subsequent calls to sem_wait(), sem_trywait(), sem_post(), and sem_destroy(). This semaphore remains usable until the semaphore is destroyed.

If pshared is non-zero, then the semaphore is sharable between threads. If the semaphore is not being shared between threads, the application should set pshared to 0 .

## RETURN VALUES

If successful, sem_init() returns 0 and initializes the semaphore in sem; otherwise it returns -1 and sets errno to indicate the error condition.

## ERRORS

EINVAL
  value exceeds SEM_VALUE_MAX.

## SEE ALSO

sem_destroy(), sem_post(), sem_wait()

## NOTES

Currently, semaphores are shared between threads. The value of the pshared argument is ignored.

#### Home page (Kernel)

## < Copyright Rowebots Research Inc. and Multiprocessor Toolsmiths Inc. 1987-2018 >