summaryrefslogtreecommitdiff
path: root/ocaml-binary-annot/testsuite/tests/lib-threads/test9.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml-binary-annot/testsuite/tests/lib-threads/test9.ml')
-rw-r--r--ocaml-binary-annot/testsuite/tests/lib-threads/test9.ml26
1 files changed, 26 insertions, 0 deletions
diff --git a/ocaml-binary-annot/testsuite/tests/lib-threads/test9.ml b/ocaml-binary-annot/testsuite/tests/lib-threads/test9.ml
new file mode 100644
index 0000000000..1f80beb8f8
--- /dev/null
+++ b/ocaml-binary-annot/testsuite/tests/lib-threads/test9.ml
@@ -0,0 +1,26 @@
+open Event
+
+type 'a swap_chan = ('a * 'a channel) channel
+
+let swap msg_out ch =
+ guard (fun () ->
+ let ic = new_channel() in
+ choose [
+ wrap (receive ch) (fun (msg_in, oc) -> sync (send oc msg_out); msg_in);
+ wrap (send ch (msg_out, ic)) (fun () -> sync (receive ic))
+ ])
+
+let ch = new_channel()
+
+let f () =
+ let res = sync (swap "F" ch) in
+ print_string "f "; print_string res; print_newline()
+
+let g () =
+ let res = sync (swap "G" ch) in
+ print_string "g "; print_string res; print_newline()
+
+let _ =
+ let id = Thread.create f () in
+ g ();
+ Thread.join id