summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--otherlibs/threads/Tests/Makefile6
-rw-r--r--otherlibs/threads/Tests/sieve.ml31
-rw-r--r--otherlibs/threads/Tests/test3.ml6
-rw-r--r--otherlibs/threads/Tests/test4.ml2
-rw-r--r--otherlibs/threads/Tests/test5.ml3
-rw-r--r--otherlibs/threads/Tests/test6.ml3
-rw-r--r--otherlibs/threads/Tests/torture.ml2
7 files changed, 42 insertions, 11 deletions
diff --git a/otherlibs/threads/Tests/Makefile b/otherlibs/threads/Tests/Makefile
index 77ccdcce0..44ba2fa73 100644
--- a/otherlibs/threads/Tests/Makefile
+++ b/otherlibs/threads/Tests/Makefile
@@ -1,4 +1,4 @@
-PROGS=test1.byt test2.byt test3.byt test4.byt test5.byt test6.byt test7.byt test8.byt test9.byt testA.byt torture.byt
+PROGS=test1.byt test2.byt test3.byt test4.byt test5.byt test6.byt test7.byt test8.byt test9.byt testA.byt sieve.byt
include ../../../config/Makefile
@@ -8,11 +8,11 @@ clean:
rm -f *.cm* *.byt
sorts.byt: sorts.ml
- cslc -custom -o sorts.byt -I .. -I ../../graph threads.cma graphics.cma sorts.ml ../libthreads.a ../../graph/libgraphics.a $(X11_LINK) $(PTHREADS_LINK)
+ cslc -custom -o sorts.byt -I .. -I ../../graph threads.cma graphics.cma sorts.ml ../libthreads.a ../../graph/libgraphics.a $(X11_LINK)
.SUFFIXES: .ml .byt
.ml.byt:
- cslc -custom -o $*.byt -I .. -I ../../unix unix.cma threads.cma $*.ml ../libthreads.a ../../unix/libunix.a $(PTHREADS_LINK)
+ cslc -custom -o $*.byt -I .. threads.cma $*.ml ../libthreads.a
$(PROGS): ../threads.cma ../libthreads.a
diff --git a/otherlibs/threads/Tests/sieve.ml b/otherlibs/threads/Tests/sieve.ml
new file mode 100644
index 000000000..2fe50f745
--- /dev/null
+++ b/otherlibs/threads/Tests/sieve.ml
@@ -0,0 +1,31 @@
+open Printf
+open Thread
+
+let rec integers n ch =
+ Event.sync (Event.send ch n);
+ integers (n+1) ch
+
+let rec sieve n chin chout =
+ let m = Event.sync (Event.receive chin)
+ in if m mod n = 0
+ then sieve n chin chout
+ else Event.sync (Event.send chout m);
+ sieve n chin chout
+
+let rec print_primes ch max =
+ let n = Event.sync (Event.receive ch)
+ in if n > max
+ then ()
+ else begin
+ printf "%d\n" n; flush stdout;
+ let ch_after_n = Event.new_channel ()
+ in new (sieve n ch) ch_after_n;
+ print_primes ch_after_n max
+ end
+
+let go max =
+ let ch = Event.new_channel ()
+ in new (integers 2) ch;
+ print_primes ch max;;
+
+let _ = go 1000
diff --git a/otherlibs/threads/Tests/test3.ml b/otherlibs/threads/Tests/test3.ml
index 19002305c..5f37775a5 100644
--- a/otherlibs/threads/Tests/test3.ml
+++ b/otherlibs/threads/Tests/test3.ml
@@ -1,8 +1,8 @@
let print_message delay c =
while true do
- print_char c; flush stdout; Unix.sleep delay
+ print_char c; flush stdout; Thread.delay delay
done
let _ =
- Thread.new (print_message 2) 'a';
- print_message 3 'b'
+ Thread.new (print_message 0.6666666666) 'a';
+ print_message 1.0 'b'
diff --git a/otherlibs/threads/Tests/test4.ml b/otherlibs/threads/Tests/test4.ml
index b564dc53b..2c9fedbef 100644
--- a/otherlibs/threads/Tests/test4.ml
+++ b/otherlibs/threads/Tests/test4.ml
@@ -1,3 +1,5 @@
+open ThreadIO
+
let rec fib n = if n <= 2 then 1 else fib(n-1) + fib(n-2)
let fibtask n =
diff --git a/otherlibs/threads/Tests/test5.ml b/otherlibs/threads/Tests/test5.ml
index 38327ffa0..a1ebcefdf 100644
--- a/otherlibs/threads/Tests/test5.ml
+++ b/otherlibs/threads/Tests/test5.ml
@@ -15,8 +15,7 @@ let _ =
Thread.new sender "hello";
Thread.new sender "world";
Thread.new receiver "A";
- Thread.new receiver "B";
- read_line();
+ receiver "B";
exit 0
diff --git a/otherlibs/threads/Tests/test6.ml b/otherlibs/threads/Tests/test6.ml
index 9942a4054..0d5283c4f 100644
--- a/otherlibs/threads/Tests/test6.ml
+++ b/otherlibs/threads/Tests/test6.ml
@@ -11,8 +11,7 @@ let rec f tag msg =
let _ =
Thread.new (f "A") "hello";
- Thread.new (f "B") "world";
- read_line();
+ f "B" "world";
exit 0
diff --git a/otherlibs/threads/Tests/torture.ml b/otherlibs/threads/Tests/torture.ml
index 1fbef0f69..792d07faf 100644
--- a/otherlibs/threads/Tests/torture.ml
+++ b/otherlibs/threads/Tests/torture.ml
@@ -3,7 +3,7 @@
let gc_thread () =
while true do
(* print_string "gc"; print_newline(); *)
- Gc.minor(); Thread.yield()
+ Gc.minor()
done
let stdin_thread () =