sem_init

Initializes a semaphore.

Library:LibC
Classification:POSIX
Service:Synchronization

Syntax

  #include <semaphore.h>
   
  int  sem_init  (
     sem_t         *sem,
     int            pshared,
     unsigned int   value );
  

Parameters

sem

(IN) Points to the semaphore to initialize. Returns SEM_FAILED if the initialization fails.

pshared

(IN) Specifies whether the semaphore can be shared. This feature is unsupported on NetWare and this parameter must be set to 0.

value

(IN) Specifies the number of resources that the semaphore can protect and control.

Return Values

If successful, returns zero; otherwise, returns -1 and sets errno to one of the following values:

Decimal

Constant

Description

9

EINVAL

The sem parameter is invalid.

12

ENOSPC

Insufficient resources to complete this call.

79

ENOTSUP

The pshared parameter has a value.

Remarks

Semaphores can be used to control access to a set of resources.

See Also