SEMAPHORE(2)                     System Calls                     SEMAPHORE(2)




NAME

       scount, screate, sdelete, ssignal, swait - semaphore operations


SYNOPSIS

       #include <gno/gno.h>

       int scount (int sem);
       int screate (int count);
       int sdelete (int sem);
       int ssignal (int sem);
       int swait (int sem);


DESCRIPTION

       screate  is  used to allocate a semaphore from the kernel semapore man-
       ager.  Semaphores are the most basic form of interprocess communication
       (IPC),  and these routines provide the power necessary to solve a large
       number of synchronization and communication problems.  (See an  Operat-
       ing Systems text).

       The  initial count determines how many times swait can be called before
       processes are blocked.  count must non-negative, and is usually set  to
       1.   screate returns a semaphore ID number as an integer.  This ID must
       be used in all the other semaphore calls.

       sdelete releases the specified semaphore, and returns to a ready  state
       all processes that were blocked on that semaphore.

       swait  decrements  the  value  of the semaphore (initially specified by
       count) by one.  If the semaphore count is less than zero,  the  process
       is  blocked  and queued for release by ssignal.  This is what is tradi-
       tionally referred to as a semaphore-down operation.

       ssignal increments the semaphore count by one.  If the semaphore  count
       is less than zero, ssignal unblocks a process blocked on the semaphore.
       The selection of the process to be unblocked is arbitrary; FIFO  opera-
       tion is not guaranteed.

       scount  retuns  the  current value of the semaphore referred to by sem.
       Note that depending on this value for synchronization can lead to  race
       conditions.


RETURN VALUE

       On  success,  screate  returns the semaphore identifier, scount returns
       the semaphore value, and sdelete, ssignal, and swait return zero.   All
       functions return -1 and set errno on failure.


BUGS

       There  is  currently  no mechanism for deallocating semaphores that are
       orphaned by abnormal process termination.


HISTORY

       These semaphore routines were designed for  XINU,  written  by  Douglas
       Comer.





GNO                             16 January 1997                   SEMAPHORE(2)

Man(1) output converted with man2html