reactiveml and jocaml two concurrent extensions of ocaml
play

ReactiveML and JoCaml: two concurrent extensions of OCaml Louis - PowerPoint PPT Presentation

ReactiveML and JoCaml: two concurrent extensions of OCaml Louis Mandel louis.mandel@lri.fr Laboratoire de Recherche en Informatique Universit e Paris-Sud 11 Synchron08 03/12/2008 Programming of concurrent systems General purpose


  1. ReactiveML and JoCaml: two concurrent extensions of OCaml Louis Mandel louis.mandel@lri.fr Laboratoire de Recherche en Informatique Universit´ e Paris-Sud 11 Synchron’08 – 03/12/2008

  2. Programming of concurrent systems General purpose programming language + dedicated constructs Two experiments above Ocaml: � Synchronous: ReactiveML � based on the synchronous reactive model of Boussinot � Programming systems with a lot of concurrence, communication and synchronisation � Interests: determinism, compositionnality, safety � Asynchronous: JoCaml (Luc Maranget) � Based on the join-calculus � Programming of distributed systems � Interests: parallel execution 2/21

  3. ReactiveML

  4. killable signal kill val kill : (int, int list) event let process killable p = let id = gen_id () in print_endline ("["^(string_of_int id)^"]"); do run p until kill(ids) when List.mem id ids done val killable : unit process -> unit process 4/21

  5. Dynamic creation: reminder let rec process extend to_add = await to_add(p) in run p || run (extend to_add) val extend : (’a, ’b process) event -> unit process signal to_add default process () gather (fun p q -> process (run p || run q)) val add_to_me : (unit process, unit process) event 5/21

  6. Dynamic creation with state let rec process extend to_add state = await to_add(p) in run (p state) || run (extend to_add state) val extend : (’a , (’b -> ’c process)) event -> ’b -> unit process signal to_add default (fun s -> process ()) gather (fun p q s -> process (run (p s) || run (q s))) val to_add : ((’_state -> unit process) , (’_state -> unit process)) event 6/21

  7. extensible signal add val add : ((int * (state -> unit process)), (int * (state -> unit process)) list) event let process extensible p_init state = let id = gen_id () in print_endline ("{"^(string_of_int id)^"}"); signal add_to_me default (fun s -> process ()) gather (fun p q s -> process (run (p s) || run (q s))) in run (p_init state) || run (extend add_to_me state) || loop await add(ids) in List.iter (fun (x,p) -> if x = id then emit add_to_me p) ids end val extensible : (state -> ’a process) -> state -> unit process 7/21

  8. JoCaml

  9. JoCaml: one place buffer let create () = def some(v) & get() = none() & reply v to get or none() & put(v) = some(v) & reply () to put in spawn none() ; (* buffer initially empty *) (put, get) 9/21

  10. JoCaml: infinite buffer let create () = def state(xs,y::ys) & get() = state(xs,ys) & reply y to get or state(xs,ys) & put(x) = state(x::xs,ys) & reply () to put or state(_::_ as xs,[]) & get() = state([],List.rev xs) & reply get() to get in spawn state([],[]) ; (* buffer initially empty *) (put, get) 10/21

  11. Boids Simulation of a flock of birds, a school of fish . . . Main points: • ReactiveML and JoCaml collaboration • centralized and distributed execution • channels mobility, dynamic aspects • failure detection, timeout 11/21

  12. Boids machiavel server floflo 12/21

  13. Boids machiavel server 1/[] floflo boids 1 13/21

  14. Boids machiavel server 2/[1] floflo boids 1 boids 2 14/21

  15. Boids machiavel server floflo boids 1 boids 2 15/21

  16. Boids machiavel server 3/[1;2] floflo boids 1 boids 2 boids 3 16/21

  17. Boids machiavel server floflo boids 1 boids 2 boids 3 17/21

  18. Boids machiavel server floflo boids 1 boids 3 18/21

  19. Boids machiavel server floflo boids 1 boids 3 4/[1;3] boids 4 19/21

  20. Boids machiavel server floflo boids 1 boids 3 boids 4 20/21

  21. Implementations are Available http://rml.lri.fr http://jocaml.inria.fr 21/21

  22. Asynchronous Communication let new_cell () = def state (_) & set(x) = state(Some x) & reply () to set or state (Some x) & get() = state(None) & reply x to get in spawn (state None); (set, get) val new_cell : (’a -> unit process, unit -> ’a process) let set_step, get_step = new_cell() let process generate_step = loop let n = run (get_step ()) in emit step n ; pause end 22/21

  23. 23/21

Recommend


More recommend