Nouveau test

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1795 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1997-11-20 15:31:28 +00:00
parent 5721a56975
commit 45638e8f80
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
let sieve primes=
Event.sync (Event.send primes 0);
Event.sync (Event.send primes 1);
Event.sync (Event.send primes 2);
let integers = Event.new_channel () in
let rec enumerate n=
Event.sync (Event.send integers n);
enumerate (n + 2)
and filter inpout =
let n = Event.sync (Event.receive inpout)
(* On prepare le terrain pour l'appel recursif
*)
and output = Event.new_channel () in
(* Celui qui etait en tete du crible est premier *)
Event.sync (Event.send primes n);
Thread.create filter output;
(* On elimine de la sortie ceux qui sont des multiples de n *)
while true do
let m = Event.sync (Event.receive inpout) in
(* print_int n; print_string ": "; print_int m; print_newline(); *)
if (m mod n) = 0
then ()
else ((Event.sync (Event.send output m));())
done in
Thread.create filter integers;
Thread.create enumerate 3
let premiers = Event.new_channel ()
let main _ =
Thread.create sieve premiers;
while true do
for i = 1 to 100 do
let n = Event.sync (Event.receive premiers) in
print_int n; print_newline()
done;
exit 0
done
let _ =
try main ()
with _ -> exit 0;;