diff --git a/dev/moonpool/Moonpool/Chan/index.html b/dev/moonpool/Moonpool/Chan/index.html index d59ef2bb..bf57d4b7 100644 --- a/dev/moonpool/Moonpool/Chan/index.html +++ b/dev/moonpool/Moonpool/Chan/index.html @@ -1,2 +1,2 @@ -
Moonpool.ChanChannels.
Channels are pipelines of values where threads can push into one end, and pull from the other end.
Unlike Moonpool.Blocking_queue, channels are designed so that pushing never blocks, and pop'ing values returns a future.
type 'a or_error = 'a Fut.or_errorval create : unit -> 'a tCreate a channel.
val push : 'a t -> 'a -> unitpush chan x pushes x into chan. This does not block.
Pop an element. This returns a future that will be fulfilled when an element is available.
val try_pop : 'a t -> 'a optiontry_pop chan pops and return an element if one is available immediately. Otherwise it returns None.
val pop_block_exn : 'a t -> 'aLike pop, but blocks if an element is not available immediately. The precautions around blocking from inside a thread pool are the same as explained in Fut.wait_block.
val close : _ t -> unitClose the channel. Further push and pop calls will fail. This is idempotent.
Moonpool.ChanChannels.
Channels are pipelines of values where threads can push into one end, and pull from the other end.
Unlike Moonpool.Blocking_queue, channels are designed so that pushing never blocks, and pop'ing values returns a future.
type 'a or_error = 'a Fut.or_errorval create : unit -> 'a tCreate a channel.
val push : 'a t -> 'a -> unitpush chan x pushes x into chan. This does not block.
Pop an element. This returns a future that will be fulfilled when an element is available.
val try_pop : 'a t -> 'a optiontry_pop chan pops and return an element if one is available immediately. Otherwise it returns None.
val pop_block_exn : 'a t -> 'aLike pop, but blocks if an element is not available immediately. The precautions around blocking from inside a thread pool are the same as explained in Fut.wait_block.
val close : _ t -> unitClose the channel. Further push and pop calls will fail. This is idempotent.
Moonpool.Fork_joinFork-join primitives.
NOTE These are only available on OCaml 5.0 and above.
Moonpool.Fork_joinFork-join primitives.
NOTE These are only available on OCaml 5.0 and above.
both f g runs f() and g(), potentially in parallel, and returns their result when both are done. If any of f() and g() fails, then the whole computation fails.
This must be run from within the pool: for example, inside Pool.run or inside a Fut.spawn computation. This is because it relies on an effect handler to be installed.
NOTE this is only available on OCaml 5.
Same as both f g |> ignore.
NOTE this is only available on OCaml 5.
for_ n f is the parallel version of for i=0 to n-1 do f i done.
f is called with parameters low and high and must use them like so:
for j = low to high do (* … actual work *) done . If chunk_size=1 then low=high and the loop is not actually needed.
NOTE this is only available on OCaml 5.
all_array fs runs all functions in fs in tasks, and waits for all the results.
NOTE this is only available on OCaml 5.
all_list fs runs all functions in fs in tasks, and waits for all the results.
NOTE this is only available on OCaml 5.
all_init n f runs functions f 0, f 1, … f (n-1) in tasks, and waits for all the results.
NOTE this is only available on OCaml 5.
map_array f arr is like Array.map f arr, but runs in parallel.
NOTE this is only available on OCaml 5.
Moonpool.FutFutures.
A future of type 'a t represents the result of a computation that will yield a value of type 'a.
Typically, the computation is running on a thread pool Runner.t and will proceed on some worker. Once set, a future cannot change. It either succeeds (storing a Ok x with x: 'a), or fail (storing a Error (exn, bt) with an exception and the corresponding backtrace).
Combinators such as map and join_array can be used to produce futures from other futures (in a monadic way). Some combinators take a on argument to specify a runner on which the intermediate computation takes place; for example map ~on:pool ~f fut maps the value in fut using function f, applicatively; the call to f happens on the runner pool (once fut resolves successfully with a value).
type 'a or_error = ('a, exn * Stdlib.Printexc.raw_backtrace) resulton_result fut f registers f to be called in the future when fut is set ; or calls f immediately if fut is already set.
Fullfill the promise, setting the future at the same time.
Fullfill the promise, setting the future at the same time. Does nothing if the promise is already fulfilled.
val return : 'a -> 'a tAlready settled future, with a result
val fail : exn -> Stdlib.Printexc.raw_backtrace -> _ tAlready settled future, with a failure
val is_resolved : _ t -> boolis_resolved fut is true iff fut is resolved.
peek fut returns Some r if fut is currently resolved with r, and None if fut is not resolved yet.
get_or_fail fut obtains the result from fut if it's fulfilled (i.e. if peek fut returns Some res, get_or_fail fut returns res).
val get_or_fail_exn : 'a t -> 'aget_or_fail_exn fut obtains the result from fut if it's fulfilled, like get_or_fail. If the result is an Error _, the exception inside is re-raised.
val is_done : _ t -> boolIs the future resolved? This is the same as peek fut |> Option.is_some.
spaw ~on f runs f() on the given runner on, and return a future that will hold its result.
reify_error fut turns a failing future into a non-failing one that contain Error (exn, bt). A non-failing future returning x is turned into Ok x
map ?on ~f fut returns a new future fut2 that resolves with f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind ?on ~f fut returns a new future fut2 that resolves like the future f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind_reify_error ?on ~f fut returns a new future fut2 that resolves like the future f (Ok x) if fut resolved with x; and resolves like the future f (Error (exn, bt)) if fut fails with exn and backtrace bt.
join fut is fut >>= Fun.id. It joins the inner layer of the future.
both a b succeeds with x, y if a succeeds with x and b succeeds with y, or fails if any of them fails.
choose a b succeeds Left x or Right y if a succeeds with x or b succeeds with y, or fails if both of them fails. If they both succeed, it is not specified which result is used.
choose_same a b succeeds with the value of one of a or b if they succeed, or fails if both fail. If they both succeed, it is not specified which result is used.
Wait for all the futures in the array. Fails if any future fails.
Wait for all the futures in the list. Fails if any future fails.
wait_array arr waits for all futures in arr to resolve. It discards the individual results of futures in arr. It fails if any future fails.
wait_list l waits for all futures in l to resolve. It discards the individual results of futures in l. It fails if any future fails.
for_ ~on n f runs f 0, f 1, …, f (n-1) on the runner, and returns a future that resolves when all the tasks have resolved, or fails as soon as one task has failed.
for_array ~on arr f runs f 0 arr.(0), …, f (n-1) arr.(n-1) in the runner (where n = Array.length arr), and returns a future that resolves when all the tasks are done, or fails if any of them fails.
for_list ~on l f is like for_array ~on (Array.of_list l) f.
NOTE This is only available on OCaml 5.
wait_block fut blocks the current thread until fut is resolved, and returns its value.
NOTE: A word of warning: this will monopolize the calling thread until the future resolves. This can also easily cause deadlocks, if enough threads in a pool call wait_block on futures running on the same pool or a pool depending on it.
A good rule to avoid deadlocks is to run this from outside of any pool, or to have an acyclic order between pools where wait_block is only called from a pool on futures evaluated in a pool that comes lower in the hierarchy. If this rule is broken, it is possible for all threads in a pool to wait for futures that can only make progress on these same threads, hence the deadlock.
val wait_block_exn : 'a t -> 'aSame as wait_block but re-raises the exception if the future failed.
module type INFIX = sig ... endmodule Infix_local : INFIXOperators that run on the same thread as the first future.
Make infix combinators, with intermediate computations running on the given pool.
Moonpool.FutFutures.
A future of type 'a t represents the result of a computation that will yield a value of type 'a.
Typically, the computation is running on a thread pool Runner.t and will proceed on some worker. Once set, a future cannot change. It either succeeds (storing a Ok x with x: 'a), or fail (storing a Error (exn, bt) with an exception and the corresponding backtrace).
Combinators such as map and join_array can be used to produce futures from other futures (in a monadic way). Some combinators take a on argument to specify a runner on which the intermediate computation takes place; for example map ~on:pool ~f fut maps the value in fut using function f, applicatively; the call to f happens on the runner pool (once fut resolves successfully with a value).
type 'a or_error = ('a, exn * Stdlib.Printexc.raw_backtrace) resulton_result fut f registers f to be called in the future when fut is set ; or calls f immediately if fut is already set.
Fullfill the promise, setting the future at the same time.
Fullfill the promise, setting the future at the same time. Does nothing if the promise is already fulfilled.
val return : 'a -> 'a tAlready settled future, with a result
val fail : exn -> Stdlib.Printexc.raw_backtrace -> _ tAlready settled future, with a failure
val is_resolved : _ t -> boolis_resolved fut is true iff fut is resolved.
peek fut returns Some r if fut is currently resolved with r, and None if fut is not resolved yet.
get_or_fail fut obtains the result from fut if it's fulfilled (i.e. if peek fut returns Some res, get_or_fail fut returns res).
val get_or_fail_exn : 'a t -> 'aget_or_fail_exn fut obtains the result from fut if it's fulfilled, like get_or_fail. If the result is an Error _, the exception inside is re-raised.
val is_done : _ t -> boolIs the future resolved? This is the same as peek fut |> Option.is_some.
spaw ~on f runs f() on the given runner on, and return a future that will hold its result.
reify_error fut turns a failing future into a non-failing one that contain Error (exn, bt). A non-failing future returning x is turned into Ok x
map ?on ~f fut returns a new future fut2 that resolves with f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind ?on ~f fut returns a new future fut2 that resolves like the future f x if fut resolved with x; and fails with e if fut fails with e or f x raises e.
bind_reify_error ?on ~f fut returns a new future fut2 that resolves like the future f (Ok x) if fut resolved with x; and resolves like the future f (Error (exn, bt)) if fut fails with exn and backtrace bt.
join fut is fut >>= Fun.id. It joins the inner layer of the future.
both a b succeeds with x, y if a succeeds with x and b succeeds with y, or fails if any of them fails.
choose a b succeeds Left x or Right y if a succeeds with x or b succeeds with y, or fails if both of them fails. If they both succeed, it is not specified which result is used.
choose_same a b succeeds with the value of one of a or b if they succeed, or fails if both fail. If they both succeed, it is not specified which result is used.
Wait for all the futures in the array. Fails if any future fails.
Wait for all the futures in the list. Fails if any future fails.
wait_array arr waits for all futures in arr to resolve. It discards the individual results of futures in arr. It fails if any future fails.
wait_list l waits for all futures in l to resolve. It discards the individual results of futures in l. It fails if any future fails.
for_ ~on n f runs f 0, f 1, …, f (n-1) on the runner, and returns a future that resolves when all the tasks have resolved, or fails as soon as one task has failed.
for_array ~on arr f runs f 0 arr.(0), …, f (n-1) arr.(n-1) in the runner (where n = Array.length arr), and returns a future that resolves when all the tasks are done, or fails if any of them fails.
for_list ~on l f is like for_array ~on (Array.of_list l) f.
NOTE This is only available on OCaml 5.
val await : 'a t -> 'aawait fut suspends the current tasks until fut is fulfilled, then resumes the task on this same runner.
This must only be run from inside the runner itself. The runner must support Suspend_. NOTE: only on OCaml 5.x
wait_block fut blocks the current thread until fut is resolved, and returns its value.
NOTE: A word of warning: this will monopolize the calling thread until the future resolves. This can also easily cause deadlocks, if enough threads in a pool call wait_block on futures running on the same pool or a pool depending on it.
A good rule to avoid deadlocks is to run this from outside of any pool, or to have an acyclic order between pools where wait_block is only called from a pool on futures evaluated in a pool that comes lower in the hierarchy. If this rule is broken, it is possible for all threads in a pool to wait for futures that can only make progress on these same threads, hence the deadlock.
val wait_block_exn : 'a t -> 'aSame as wait_block but re-raises the exception if the future failed.
module type INFIX = sig ... endmodule Infix_local : INFIXOperators that run on the same thread as the first future.
Make infix combinators, with intermediate computations running on the given pool.
Moonpool.LockMutex-protected resource.
val create : 'a -> 'a tCreate a new protected value.
val with_ : 'a t -> ('a -> 'b) -> 'bwith_ l f runs f x where x is the value protected with the lock l, in a critical section. If f x fails, with_lock l f fails too but the lock is released.
val update : 'a t -> ('a -> 'a) -> unitupdate l f replaces the content x of l with f x, while protected by the mutex.
val update_map : 'a t -> ('a -> 'a * 'b) -> 'bupdate_map l f computes x', y = f (get l), then puts x' in l and returns y, while protected by the mutex.
val get : 'a t -> 'aAtomically get the value in the lock. The value that is returned isn't protected!
Moonpool.LockMutex-protected resource.
val create : 'a -> 'a tCreate a new protected value.
val with_ : 'a t -> ('a -> 'b) -> 'bwith_ l f runs f x where x is the value protected with the lock l, in a critical section. If f x fails, with_lock l f fails too but the lock is released.
val update : 'a t -> ('a -> 'a) -> unitupdate l f replaces the content x of l with f x, while protected by the mutex.
val update_map : 'a t -> ('a -> 'a * 'b) -> 'bupdate_map l f computes x', y = f (get l), then puts x' in l and returns y, while protected by the mutex.
val mutex : _ t -> Stdlib.Mutex.tUnderlying mutex.
val get : 'a t -> 'aAtomically get the value in the lock. The value that is returned isn't protected!
Moonpool.Suspend_Suspensions.
This is only going to work on OCaml 5.x.
NOTE: this is not stable for now.
(Private) suspending tasks using Effects.
This module is an implementation detail of Moonpool and should not be used outside of it, except by experts to implement Runner.
type suspension = (unit, exn * Stdlib.Printexc.raw_backtrace) result -> unitA suspended computation
The handler that knows what to do with the suspended computation.
The handler is given two things:
run function that can be used to start tasks to perform some computation.This means that a fork-join primitive, for example, can use a single call to suspend to:
run to start all the tasks. Typically run is called multiple times, which is where the "fork" part comes from. Each call to run potentially runs in parallel with the other calls. The calls must coordinate so that, once they are all done, the suspended caller is resumed with the aggregated result of the computation.val with_suspend :
+Suspend_ (moonpool.Moonpool.Suspend_) Module Moonpool.Suspend_
Suspensions.
This is only going to work on OCaml 5.x.
NOTE: this is not stable for now.
(Private) suspending tasks using Effects.
This module is an implementation detail of Moonpool and should not be used outside of it, except by experts to implement Runner.
type suspension = (unit, exn * Stdlib.Printexc.raw_backtrace) result -> unitA suspended computation
The handler that knows what to do with the suspended computation.
The handler is given two things:
- the suspended computation (which can be resumed with a result eventually);
- a
run function that can be used to start tasks to perform some computation.
This means that a fork-join primitive, for example, can use a single call to suspend to:
- suspend the caller until the fork-join is done
- use
run to start all the tasks. Typically run is called multiple times, which is where the "fork" part comes from. Each call to run potentially runs in parallel with the other calls. The calls must coordinate so that, once they are all done, the suspended caller is resumed with the aggregated result of the computation.
type Stdlib.Effect.t += | Suspend : suspension_handler -> unit Stdlib.Effect.t(*The effect used to suspend the current thread and pass it, suspended, to the handler. The handler will ensure that the suspension is resumed later once some computation has been done.
*)
val suspend : suspension_handler -> unitsuspend h jumps back to the nearest with_suspend and calls h.handle with the current continuation k and a task runner function.
val with_suspend :
run:(with_handler:bool -> task -> unit) ->
(unit -> unit) ->
unitwith_suspend ~run f runs f() in an environment where suspend will work. If f() suspends with suspension handler h, this calls h ~run k where k is the suspension.
This will not do anything on OCaml 4.x.
\ No newline at end of file
diff --git a/dev/ocaml/Arg_helper/Make/argument-1-S/Key/Map/index.html b/dev/ocaml/Arg_helper/Make/argument-1-S/Key/Map/index.html
index 3d3fffe8..113a9884 100644
--- a/dev/ocaml/Arg_helper/Make/argument-1-S/Key/Map/index.html
+++ b/dev/ocaml/Arg_helper/Make/argument-1-S/Key/Map/index.html
@@ -5,4 +5,4 @@
'b t ->
'c tmerge f m1 m2 computes a map whose keys are a subset of the keys of m1 and of m2. The presence of each such binding, and the corresponding value, is determined with the function f. In terms of the find_opt operation, we have find_opt x (merge f m1 m2) = f x (find_opt x m1) (find_opt x m2) for any key x, provided that f x None None = None.
union f m1 m2 computes a map whose keys are a subset of the keys of m1 and of m2. When the same binding is defined in both arguments, the function f is used to combine them. This is a special case of merge: union f m1 m2 is equivalent to merge f' m1 m2, where
f' _key None None = Nonef' _key (Some v) None = Some vf' _key None (Some v) = Some vf' key (Some v1) (Some v2) = f key v1 v2Total ordering between maps. The first argument is a total ordering used to compare data associated with equal keys in the two maps.
equal cmp m1 m2 tests whether the maps m1 and m2 are equal, that is, contain equal keys and associate them with equal data. cmp is the equality predicate used to compare the data associated with the keys.
iter f m applies f to all bindings in map m. f receives the key as first argument, and the associated value as second argument. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys.
fold f m init computes (f kN dN ... (f k1 d1 init)...), where k1 ... kN are the keys of all bindings in m (in increasing order), and d1 ... dN are the associated data.
for_all f m checks if all the bindings of the map satisfy the predicate f.
exists f m checks if at least one binding of the map satisfies the predicate f.
filter f m returns the map with all the bindings in m that satisfy predicate p. If every binding in m satisfies f, m is returned unchanged (the result of the function is then physically equal to m)
filter_map f m applies the function f to every binding of m, and builds a map from the results. For each binding (k, v) in the input map:
f k v is None then k is not in the result,f k v is Some v' then the binding (k, v') is in the output map.For example, the following function on maps whose values are lists
filter_map
(fun _k li -> match li with [] -> None | _::tl -> Some tl)
- mdrops all bindings of m whose value is an empty list, and pops the first element of each value that is non-empty.
partition f m returns a pair of maps (m1, m2), where m1 contains all the bindings of m that satisfy the predicate f, and m2 is the map with all the bindings of m that do not satisfy f.
val cardinal : 'a t -> intReturn the number of bindings of a map.
Return the list of all bindings of the given map. The returned list is sorted in increasing order of keys with respect to the ordering Ord.compare, where Ord is the argument given to Stdlib.Map.Make.
Return the binding with the smallest key in a given map (with respect to the Ord.compare ordering), or raise Not_found if the map is empty.
Return the binding with the smallest key in the given map (with respect to the Ord.compare ordering), or None if the map is empty.
Same as min_binding, but returns the binding with the largest key in the given map.
Same as min_binding_opt, but returns the binding with the largest key in the given map.
Return one binding of the given map, or raise Not_found if the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.
Return one binding of the given map, or None if the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.
split x m returns a triple (l, data, r), where l is the map with all the bindings of m whose key is strictly less than x; r is the map with all the bindings of m whose key is strictly greater than x; data is None if m contains no binding for x, or Some v if m binds v to x.
find x m returns the current value of x in m, or raises Not_found if no binding for x exists.
find_opt x m returns Some v if the current value of x in m is v, or None if no binding for x exists.
find_first f m, where f is a monotonically increasing function, returns the binding of m with the lowest key k such that f k, or raises Not_found if no such key exists.
For example, find_first (fun k -> Ord.compare k x >= 0) m will return the first binding k, v of m where Ord.compare k x >= 0 (intuitively: k >= x), or raise Not_found if x is greater than any element of m.
find_first_opt f m, where f is a monotonically increasing function, returns an option containing the binding of m with the lowest key k such that f k, or None if no such key exists.
find_last f m, where f is a monotonically decreasing function, returns the binding of m with the highest key k such that f k, or raises Not_found if no such key exists.
find_last_opt f m, where f is a monotonically decreasing function, returns an option containing the binding of m with the highest key k such that f k, or None if no such key exists.
map f m returns a map with same domain as m, where the associated value a of all bindings of m has been replaced by the result of the application of f to a. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys.
Same as map, but the function receives as arguments both the key and the associated value for each binding of the map.
to_seq_from k m iterates on a subset of the bindings of m, in ascending order of keys, from key k or above.
drops all bindings of m whose value is an empty list, and pops the first element of each value that is non-empty.
partition f m returns a pair of maps (m1, m2), where m1 contains all the bindings of m that satisfy the predicate f, and m2 is the map with all the bindings of m that do not satisfy f.
val cardinal : 'a t -> intReturn the number of bindings of a map.
Return the list of all bindings of the given map. The returned list is sorted in increasing order of keys with respect to the ordering Ord.compare, where Ord is the argument given to Map.Make.
Return the binding with the smallest key in a given map (with respect to the Ord.compare ordering), or raise Not_found if the map is empty.
Return the binding with the smallest key in the given map (with respect to the Ord.compare ordering), or None if the map is empty.
Same as min_binding, but returns the binding with the largest key in the given map.
Same as min_binding_opt, but returns the binding with the largest key in the given map.
Return one binding of the given map, or raise Not_found if the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.
Return one binding of the given map, or None if the map is empty. Which binding is chosen is unspecified, but equal bindings will be chosen for equal maps.
split x m returns a triple (l, data, r), where l is the map with all the bindings of m whose key is strictly less than x; r is the map with all the bindings of m whose key is strictly greater than x; data is None if m contains no binding for x, or Some v if m binds v to x.
find x m returns the current value of x in m, or raises Not_found if no binding for x exists.
find_opt x m returns Some v if the current value of x in m is v, or None if no binding for x exists.
find_first f m, where f is a monotonically increasing function, returns the binding of m with the lowest key k such that f k, or raises Not_found if no such key exists.
For example, find_first (fun k -> Ord.compare k x >= 0) m will return the first binding k, v of m where Ord.compare k x >= 0 (intuitively: k >= x), or raise Not_found if x is greater than any element of m.
find_first_opt f m, where f is a monotonically increasing function, returns an option containing the binding of m with the lowest key k such that f k, or None if no such key exists.
find_last f m, where f is a monotonically decreasing function, returns the binding of m with the highest key k such that f k, or raises Not_found if no such key exists.
find_last_opt f m, where f is a monotonically decreasing function, returns an option containing the binding of m with the highest key k such that f k, or None if no such key exists.
map f m returns a map with same domain as m, where the associated value a of all bindings of m has been replaced by the result of the application of f to a. The bindings are passed to f in increasing order with respect to the ordering over the type of the keys.
Same as map, but the function receives as arguments both the key and the associated value for each binding of the map.
to_seq_from k m iterates on a subset of the bindings of m, in ascending order of keys, from key k or above.