module Netsys_sem:sig
..end
Netsys_posix
.
Note that on OS X named semaphores have a max name length of
31 characters (including the / at the beginning), and that
Netsys_sem
uses 9 characters for its own purposes, leaving
22 characters for the prefix. (On other OS this is less restricted.)
val have_anon_semaphores : unit -> bool
true
if anonymous semaphores are supported on this
system, either natively or emulated via named semaphores.val sem_value_max : int
max_int
val sem_size : int
sizeof(sem_t)
)type
container
typeprefix =
string
type
anon_semaphore
typesem_open_flag =
Netsys_posix.sem_open_flag
=
| |
SEM_O_CREAT |
| |
SEM_O_EXCL |
val container : prefix -> container
container prefix
: The prefix shall identify the container uniquely.
Once can e.g. use the path of the shared memory object. The prefix
is used to construct names for persistent objects.
Note that containers have kernel persistence! They are not
automatically deleted when the process finishes. Call drop
to delete containers, or create_container
to force their
creation as fresh objects.
If the container does not exist yet, it is created. Otherwise the
container is just opened.
val create_container : prefix -> container
create_container prefix
: Like container
, but the container is
always created. A previous instance is first deleted.val prefix : container -> prefix
val drop : container -> unit
This function is a no-op if the OS supports anonymous semaphores
directly (because in this case the deletion of the container will
automatically destroy the semaphores).
val unlink : prefix -> unit
val sem_init : container ->
Netsys_types.memory -> int -> bool -> int -> anon_semaphore
sem_init cont mem pos pshared init_value
: Initializes the memory
at position pos
to pos + sem_size() - 1
as anonymous semaphore.
If pshared
the semaphore is shared between processes.
init_value
is the initial non-negative value (max is
sem_value_max
).val sem_destroy : container -> anon_semaphore -> unit
val as_sem : container ->
Netsys_types.memory -> int -> anon_semaphore
as_sem mem pos
: Interprets the memory at position pos
to pos + sem_size() - 1
as anonymous semaphore.
The memory region must already have been initialized.val sem_getvalue : anon_semaphore -> int
int
, an EINVAL
error is returned.
The returned value is non-negative - if the underlying POSIX function reports a negative value zero is returned instead.
Unavailable on MacOS.
val sem_post : anon_semaphore -> unit
typesem_wait_behavior =
Netsys_posix.sem_wait_behavior
=
| |
SEM_WAIT_BLOCK |
| |
SEM_WAIT_NONBLOCK |
val sem_wait : anon_semaphore -> sem_wait_behavior -> unit
SEM_WAIT_BLOCK
is given, the function
waits until another process or thread posts. If SEM_WAIT_NONBLOCK
the error EAGAIN
is returned.
sem_wait
may be interrupted by signals.
module Debug:sig
..end