Skip to content

Commit c663f51

Browse files
committed
Patch STM_thread with Gc.Memprof hack to increase interleavings
1 parent dafe9f9 commit c663f51

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/STM_thread.ml

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ module MakeExt (Spec: SpecExt) = struct
1111

1212
let arb_cmds_triple = arb_cmds_triple
1313

14+
let alloc_callback _src =
15+
Thread.yield ();
16+
None
17+
18+
let yield_tracker =
19+
Gc.Memprof.{ null_tracker with alloc_minor = alloc_callback;
20+
alloc_major = alloc_callback; }
21+
1422
(* [interp_sut_res] specialized for [Threads] *)
1523
let rec interp_sut_res sut cs = match cs with
1624
| [] -> []
@@ -23,13 +31,15 @@ module MakeExt (Spec: SpecExt) = struct
2331
let agree_prop_conc (seq_pref,cmds1,cmds2) =
2432
let sut = Spec.init_sut () in
2533
let obs1,obs2 = ref (Error ThreadNotFinished), ref (Error ThreadNotFinished) in
34+
let _ = Gc.Memprof.start ~sampling_rate:1e-3 ~callstack_size:0 yield_tracker in
2635
let pref_obs = Spec.wrap_cmd_seq @@ fun () -> interp_sut_res sut seq_pref in
2736
let wait = ref true in
2837
let th1 = Thread.create (fun () -> Spec.wrap_cmd_seq @@ fun () -> while !wait do Thread.yield () done; obs1 := try Ok (interp_sut_res sut cmds1) with exn -> Error exn) () in
2938
let th2 = Thread.create (fun () -> Spec.wrap_cmd_seq @@ fun () -> wait := false; obs2 := try Ok (interp_sut_res sut cmds2) with exn -> Error exn) () in
30-
let () = Thread.join th1 in
31-
let () = Thread.join th2 in
32-
let () = Spec.cleanup sut in
39+
Thread.join th1;
40+
Thread.join th2;
41+
Gc.Memprof.stop ();
42+
Spec.cleanup sut;
3343
let obs1 = match !obs1 with Ok v -> v | Error exn -> raise exn in
3444
let obs2 = match !obs2 with Ok v -> v | Error exn -> raise exn in
3545
check_obs pref_obs obs1 obs2 Spec.init_state

0 commit comments

Comments
 (0)