sema_init

Initializes a semaphore.

Library:LibC
Classification:UNIX International
Service:Synchronization

Syntax

  #include <synch.h>
   
  int   sema_init  (
     sema_t        *sp,
     unsigned int   count,
     int            type,
     void          *arg );
  

Parameters

sp

(IN) Points to the semaphore to initialize.

count

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

type

(IN) Specifies the type of mutex with one of the following flags:

Flag

Value

Description

USYNC_THREAD

0

The semaphore is known only to the owning process.

USYNC_PROCESS

1

Unsupported. The semaphore can be shared between processes.

arg

(IN) Reserved for future use. Set to NULL.

Return Values

If successful, returns zero; otherwise, returns a nonzero error code:

Decimal

Constant

Description

79

ENOTSUP

The type parameter has an invalid value.

Remarks

Semaphores can be used to control access to a set of resources. Once initialized, the semaphore can be used any number of times without being reinitialized.

UI semaphores are not recursive. A thread can block itself if it attempts to reacquire a semaphore that it has already acquired.

See Also