package picos_mux
Sample schedulers for Picos
Install
dune-project
Dependency
Authors
Maintainers
Sources
picos-0.6.0.tbz
sha256=3f5a08199cf65c2dae2f7d68f3877178f1da8eabf5376e15114e5a8958087dfa
sha512=ad24910c47ce614268c4268874bb918da7f8b5f03b3ad706bbf30323635262e94ddab6be24eaebbca706bfa82c0a517d4272b396459e020c185942125c9bdb7b
doc/index.html
Sample schedulers for Picos
This package contains schedulers provided as samples for Picos.
Libraries
Picos_mux_fifoBasic single-threaded effects basedPicoscompatible scheduler for OCaml 5.Picos_mux_multififoBasic multi-threaded effects basedPicoscompatible scheduler for OCaml 5.Picos_mux_randomRandomized multi-threaded effects basedPicoscompatible scheduler for OCaml 5.Picos_mux_threadBasicThreadbasedPicoscompatible scheduler for OCaml 4.
You may find these useful for both understanding the core Picos interface and for testing your own libraries implemented in Picos.
Examples
Below is a program that forks a number of fibers and records a list of the domain ids on which the fibers run:
open Picos_std_structured
module Mpscq = Picos_aux_mpscq
let main ~work () =
let dids = Mpscq.create () in
Flock.join_after begin fun () ->
for _ = 1 to 4 do
Flock.fork @@ fun () ->
let did = (Domain.self () :> int) in
Unix.sleepf work; (* <- simulate work *)
Mpscq.push dids did
done
end;
Mpscq.pop_all dids
|> List.of_seq
|> List.sort Int.compareWe can now try running the program with the sample schedulers:
# Picos_mux_fifo.run (main ~work:0.0)
- : int list = [0; 0; 0; 0]
# Picos_mux_multififo.run_on ~n_domains:4 (main ~work:0.2)
- : int list = [0; 1; 2; 3]
# Picos_mux_random.run_on ~n_domains:4 (main ~work:0.2)
- : int list = [0; 4; 5; 6]
# Picos_mux_thread.run (main ~work:0.0)
- : int list = [0; 0; 0; 0]A subtle detail above is that the Unix.sleepf call blocks the underlying thread for a moment, which makes it likely that multiple domains will be used by the multi-threaded schedulers. The results with the multi-threaded schedulers are still strictly speaking non-deterministic.