Skip to content
Snippets Groups Projects
Commit 483e953b authored by erwan's avatar erwan
Browse files

New: add the pid of the process in the local_env

parents 2e5b8b6f 776d22ab
No related branches found
No related tags found
No related merge requests found
(* Time-stamp: <modified the 12/06/2019 (at 09:54) by Erwan Jahier> *)
(* Time-stamp: <modified the 14/06/2019 (at 13:46) by Erwan Jahier> *)
(** Process programmer API *)
......
(* Time-stamp: <modified the 12/06/2019 (at 08:06) by Erwan Jahier> *)
(* Time-stamp: <modified the 14/06/2019 (at 13:46) by Erwan Jahier> *)
module Dico = Map.Make(String)
......@@ -21,6 +21,7 @@ let (get_copy: Algo.vars -> 'v t -> string -> 'v Algo.local_env) =
let (set: 'v t -> string -> 'v Algo.local_env -> 'v t) =
fun e pid lenv ->
(* Printf.printf "--> set pid %s\n" pid; flush stdout; *)
let lenv = Algo.set lenv "pid" (Algo.S pid) in
Dico.add pid lenv e
let (init:unit -> 'v t) = fun () -> Dico.empty
......
(* Time-stamp: <modified the 12/06/2019 (at 09:57) by Erwan Jahier> *)
(* Time-stamp: <modified the 14/06/2019 (at 13:45) by Erwan Jahier> *)
open Algo
open Sasacore
let (update_env_with_init : 'v Env.t -> 'v Process.t list -> 'v Env.t) =
fun e pl ->
let (aux: 'v Env.t -> 'v Process.t -> 'v Env.t) =
......
(* Time-stamp: <modified the 11/06/2019 (at 16:32) by Erwan Jahier> *)
(* Time-stamp: <modified the 14/06/2019 (at 13:26) by Erwan Jahier> *)
(* This is algo 3.1 in the book *)
......@@ -12,7 +12,7 @@ let (init_vars: neighbor list -> local_env) =
set empty_env "c" (I (Random.int k))
let verbose = false
let verbose = true
let (neigbhors_values : neighbor list -> Algo.value list) =
fun nl ->
......@@ -23,7 +23,8 @@ let (clash : Algo.value -> neighbor list -> bool) = fun v nl ->
let inl = List.map (fun n -> n.pid()) nl in
let res = List.mem v vnl in
if verbose then (
Printf.printf "%s %s in [%s] (%s)\n" (value_to_string v) (if res then "" else "not")
Printf.printf "%s %s in [%s] (%s)\n" (value_to_string v)
(if res then "" else "not")
(String.concat "," (List.map value_to_string vnl))
(String.concat "," (inl));
flush stdout
......@@ -46,7 +47,7 @@ let (free : neighbor list -> Algo.value list) = fun nl ->
let (enable_f:neighbor list -> local_env -> action list) =
fun nl e ->
if (clash (get e "c") nl) then ["conflict"] else []
let (step_f : neighbor list -> local_env -> action -> local_env) =
fun nl e a ->
let f = free nl in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment