Commit 4fca638a authored by François Bobot's avatar François Bobot
Browse files

Partial Fix for segfault of whybench

parent be12cebb
......@@ -319,7 +319,7 @@ let do_why_sync funct argument =
let c = Condition.create () in
let r = ref None in
let cb res =
Mutex.lock m; r := Some res; Mutex.unlock m; Condition.signal c in
Mutex.lock m; r := Some res; Condition.signal c; Mutex.unlock m in
do_why ~callback:cb funct argument;
Mutex.lock m; Condition.wait c m;
Mutex.lock m; Condition.wait c m; Mutex.unlock m;
Util.of_option !r
......@@ -86,7 +86,7 @@ sig
val tag : t -> tag
end
module Make (S : Weakey) = struct
module MakeWeak (S : Weakey) = struct
type key = S.t
......@@ -129,7 +129,8 @@ module Make (S : Weakey) = struct
tbl_set = H.create n;
tbl_tag = (incr c; !c) }
in
Gc.finalise tbl_final t;
(** Buggy with thread, modify an external data structure *)
(* Gc.finalise tbl_final t; *)
t
let clear t = tbl_final t; H.clear t.tbl_set
......@@ -159,3 +160,39 @@ module Make (S : Weakey) = struct
end
(* without weak but same interface *)
module MakeSimple (S : Weakey) = struct
module H = Hashtbl.Make (struct
type t = S.t
let hash k = (S.tag k).tag_tag
let equal k1 k2 = S.tag k1 == S.tag k2
end)
include H
let iterk f = iter (fun k _ -> f k)
let foldk f = fold (fun k _ -> f k)
let set = replace
let memoize n fn =
let h = create n in fun e ->
try find h e
with Not_found ->
let v = fn e in
replace h e v;
v
let memoize_option n fn =
let v = lazy (fn None) in
let fn e = fn (Some e) in
let fn = memoize n fn in
function
| Some e -> fn e
| None -> Lazy.force v
end
module Make = MakeWeak
(* module Make = MakeSimple *)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment