diff --git a/tests/dune b/tests/dune index 5ff04b6..ace0ad8 100644 --- a/tests/dune +++ b/tests/dune @@ -19,6 +19,11 @@ (modules test_simple)) (test - (name test_simple2) + (name test_conditional1) (libraries dscheck) - (modules test_simple2)) + (modules test_conditional1)) + +(test + (name test_conditional2) + (libraries dscheck) + (modules test_conditional2)) diff --git a/tests/test_simple2.ml b/tests/test_conditional1.ml similarity index 100% rename from tests/test_simple2.ml rename to tests/test_conditional1.ml diff --git a/tests/test_conditional2.ml b/tests/test_conditional2.ml new file mode 100644 index 0000000..a69a1b0 --- /dev/null +++ b/tests/test_conditional2.ml @@ -0,0 +1,25 @@ +module Atomic = Dscheck.TracedAtomic + +let test () = + let x = Atomic.make 0 in + let y = Atomic.make 0 in + let z = Atomic.make 0 in + + let tmp = ref (-1) in + Atomic.spawn (fun () -> tmp := Atomic.get x); + Atomic.spawn (fun () -> Atomic.set y 1); + + Atomic.spawn (fun () -> + let m = Atomic.get y in + if m = 0 then Atomic.set z 1); + + Atomic.spawn (fun () -> + let n = Atomic.get z in + let l = Atomic.get y in + if n = 1 then if l = 0 then Atomic.set x 1); + + Atomic.final (fun () -> + Format.printf "tmp=%d x=%d y=%d z=%d\n%!" !tmp (Atomic.get x) + (Atomic.get y) (Atomic.get z)) + +let () = Atomic.trace test