module Pfs_condition:Condition variables
Netmcore_condition(of Ocamlnet): It is possible to wait asynchronously for a condition. In order to do so, each waiter creates a named pipe. If the variable is signalled, a byte is written to the pipe, which wakes the waiter up.
Condition variables are here defined as values that reside in shared heaps
Netmcore_heap), for example in the header field of
Netmcore_array or somewhere else in heap-allocated
In order to ensure that the condition variable is in the heap, the
create_condition must be used to initialize it
create_condition requires a mutator as argument, this is
only possible by calling
create_condition from the callback of
Condition variables are special values, and cannot be copied or moved.
Condition variables are implemented on top of semaphores. Compared to
pthreads version of condition variables, the user needs here to
wait_entry slots, one for each process. An entry
can be used for all condition variables a process needs to wait for.
(Actually, such entries also exist in typical
but are hidden from the user in the thread control block. We just
don't have here a place where we could allocate process-specific
wait_entry. These entries can be used for several condition variables, so typically each process has only one entry for each heap.
wait_entry, for easier management. This set can e.g. be stored side by side with the condition variable(s). It is important that the
wait_setresides in the same shared heap as the condition variable.
val dummy_condition :
unit -> condition
val dummy_wait_set :
unit -> wait_set
wait_setis non-functional, but can be used to put something into
val create_condition :
Netmcore_heap.mutator -> condition
create m: Creates a condition variable, and pushes it to the heap, using the mutator
After being pushed to the heap, the variable can be used. It is
nonsense to copy it outside the heap.
val create_wait_set :
Netmcore_heap.mutator -> string -> wait_set
wait_setin the heap designated by the mutator.
The string argument is a prefix for the named pipe (e.g.
val alloc_wait_entry :
Netmcore_heap.mutator -> wait_set -> wait_entry
val free_wait_entry :
wait_set -> wait_entry -> unit
val pipe_file :
wait_entry -> string
val wait_e :
(unit -> 'a Uq_engines.engine) -> 'a Uq_engines.engine
wait_e we c m esys contatomically unlocks the mutex
mand suspends the calling engine on the condition variable
c. The engine will restart after the condition variable
chas been signalled. The mutex
mis locked again, at which time
contis called. The result of
cont()is the result of
At the time of calling, the
we must not be used to
wait. When allocating a separate
per process (or thread within the process) this problem does not occur.
Another important restriction: There must be at most one
wait_e per process or thread.
val signal :
condition -> unit
signal crestarts one of the processes waiting on the condition variable
val broadcast :
condition -> unit
broadcast crestarts all processes waiting on the condition variable
val destroy_condition :
condition -> unit
val destroy_wait_set :
wait_set -> unit
val serializer_heap :
Netmcore.res_id -> ser Netmcore_ref.sref
serializer_heap pool: initializes a shared structure for use with
serializer. The structure needs/must only to be initialized in one of the processes using the serializer.
val serializer :
ser Netmcore_ref.sref ->
Unixqueue.event_system -> string -> 'a Uq_engines.serializer_t
serializer heap esys: Creates a serializer that works across processes. The returned object exists in all processes using the serializer.
val int64_serializer_heap :
Netmcore.res_id -> int -> int64_ser Netmcore_ref.sref
int_serializer_heap pool n: initializes a shared structure for use with
int_serializer. The structure needs/must only to be initialized in one of the processes using the serializer. The value
nis the expected value of the number of blocking callers,
n >= 1. Higher values of
nconsume more memory and reduce the likeliness that two callers have to synchronize with each other.
val int64_serializer :
int64_ser Netmcore_ref.sref ->
Unixqueue.event_system -> string -> 'a int64_serializer_t
int_serializer heap esys: Creates a serializer that works across processes. The returned object exists in all processes using the serializer.