sembuf

Contains information about a semaphore operation.

Service:Synchronization

Structure

  #include <sys/sem.h>
  
  struct sembuf
  {
     unsigned short   sem_num;
     short            sem_op;
     short            sem_flg;
  };
  

Fields

sem_num

Specifies which semaphore and is the index into the array of sem structures referenced in the sem_base field of the semid_ds structure.

sem_op

Specifies the operation with one of the following values:

Value

Description

Zero

Causes the calling thread to sleep until the semaphore's value is 0, or in other words, has reached 100% utilization, except when the IPC_NOWAIT flag is set.

Positive

Adds the value to the semaphore.

Negative

Subtracts the value from the semaphore. The calling thread waits until the requested number of resources are free except when the IPC_NOWAIT flag is set.

sem_flg

Specifies how the semaphore operation should be performed.

Flag

Value

Description

IPC_NOWAIT

0x00000800

If set for a negative or zero sem_op operation, the calling thread returns immediately with either the resources or an error indicating that the resources are not available.

SEM_UNDO

0x00001000

If set, the operation is undone when the process exits.