module Sem:Ocaml interface to POSIX semaphores. Mimics the standard C library as met in FreeBsd 5 (seesig..end
man sem_open, man sem, etc.).
For the further reference see "ISO/IEC 9945-1:1996 (``POSIX.1'')." (find it youself ;)
Author: Paul Argentoff, argentoff@gmail.com.
Version: $Id: sem.mli 324 2005-04-19 06:38:44Z paul $
See also my homepage.
type t
val sem_open : string ->
?oflags:Unix.open_flag list ->
?mode:Unix.file_perm -> ?ival:int -> unit -> tsem_open name oflags mode ival creates or opens the named semaphore specified by
name. The returned semaphore may be used in subsequent calls to
sem_getvalue, sem_wait, sem_trywait, sem_post, and
sem_close. oflags must be either Unix.O_CREAT, Unix.O_EXCL or both.
Default values:
oflags = []mode = 0o600ival = 0val sem_close : t -> unitval sem_unlink : string -> unitval sem_post : t -> unitsem_post sem increments (unlocks) the semaphore pointed to by
sem. If there are threads blocked on the semaphore when sem_post is
called, then the highest priority thread that has been blocked the long-
est on the semaphore will be allowed to return from sem_wait.val sem_wait : t -> unitsem_wait sem decrements (locks) the semaphore pointed to by
sem, but blocks if the value of sem is zero, until the value is non-zero
and the value can be decremented.val sem_trywait : t -> unitsem_trywait sem decrements (locks) the semaphore pointed to by
sem only if the value is non-zero. Otherwise, the semaphore is not
decremented and an error is returned.val sem_getvalue : t -> intsem_getvalue sem returns a value of sem.sem_open) are common to named semaphores
and should be done by the functions documented above.val sem_init : ?semop:t option -> ?pshared:int -> ?ival:int -> unit -> tsem_init semop pshared ival initializes the unnamed semaphore. If
semop = None, returns the newly created semaphore, else re-initializes
the existing one and returns it.
The semaphore will have the value ival. A non-zero value for
pshared specifies a shared semaphore that can be used by multiple
processes, which this implementation is not capable of.
Following a successful call to sem_init, sem can be used as an argument
in subsequent calls to sem_wait, sem_trywait, sem_post, and
sem_destroy. The sem argument is no longer valid after a successful
call to sem_destroy).
Default values:
semop = Nonepshared = 0ival = 0val sem_destroy : t -> unitdestroy sem destroys the unnamed semaphore pointed to by
sem. After a successful call to sem_destroy, sem is unusable until re-
initialized by another call to sem_init.