MAJ jeu de tests

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@775 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1996-04-29 14:06:05 +00:00
parent 80bfb86576
commit 041ba4a44d
16 changed files with 49 additions and 49 deletions

View File

@ -19,13 +19,13 @@ let rec print_primes ch max =
else begin
printf "%d\n" n; flush stdout;
let ch_after_n = Event.new_channel ()
in new (sieve n ch) ch_after_n;
in Thread.create (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;
in Thread.create (integers 2) ch;
print_primes ch max;;
let _ = go 1000

View File

@ -17,7 +17,7 @@ type graphic_context =
(* Array assignment and exchange with screen update *)
let screen_mutex = Mutex.new()
let screen_mutex = Mutex.create()
let draw gc i v =
fill_rect (gc.x0 + (gc.width * i) / gc.nelts)
@ -63,17 +63,17 @@ let initialize name array maxval x y w h =
(* Main animation function *)
let display functs nelts maxval =
let a = Array.new nelts 0 in
let a = Array.create nelts 0 in
for i = 0 to nelts - 1 do
a.(i) <- Random.int maxval
done;
let num_finished = ref 0 in
let lock_finished = Mutex.new() in
let cond_finished = Condition.new() in
let lock_finished = Mutex.create() in
let cond_finished = Condition.create() in
for i = 0 to Array.length functs - 1 do
let (name, funct, x, y, w, h) = functs.(i) in
let gc = initialize name a maxval x y w h in
Thread.new
Thread.create
(fun () ->
funct gc;
Mutex.lock lock_finished;

View File

@ -8,13 +8,13 @@ type 'a prodcons =
notempty: Condition.t;
notfull: Condition.t }
let new size init =
{ buffer = Array.new size init;
lock = Mutex.new();
let create size init =
{ buffer = Array.create size init;
lock = Mutex.create();
readpos = 0;
writepos = 0;
notempty = Condition.new();
notfull = Condition.new() }
notempty = Condition.create();
notfull = Condition.create() }
let put p data =
Mutex.lock p.lock;
@ -39,7 +39,7 @@ let get p =
(* Test *)
let buff = new 20 0
let buff = create 20 0
let rec produce n =
print_int n; print_string "-->"; print_newline();
@ -52,7 +52,7 @@ let rec consume () =
consume ()
let _ =
Thread.new produce 0;
Thread.create produce 0;
consume()

View File

@ -4,6 +4,6 @@ let print_message c =
done
let _ =
let t1 = Thread.new print_message 'a' in
let t2 = Thread.new print_message 'b' in
let t1 = Thread.create print_message 'a' in
let t2 = Thread.create print_message 'b' in
Thread.join t1; Thread.join t2; exit 0

View File

@ -4,5 +4,5 @@ let print_message delay c =
done
let _ =
Thread.new (print_message 0.6666666666) 'a';
Thread.create (print_message 0.6666666666) 'a';
print_message 1.0 'b'

View File

@ -8,7 +8,7 @@ let fibtask n =
done
let _ =
Thread.new fibtask 28;
Thread.create fibtask 28;
while true do
let l = read_line () in
print_string ">> "; print_string l; print_newline()

View File

@ -12,9 +12,9 @@ let rec receiver name =
receiver name
let _ =
Thread.new sender "hello";
Thread.new sender "world";
Thread.new receiver "A";
Thread.create sender "hello";
Thread.create sender "world";
Thread.create receiver "A";
receiver "B";
exit 0

View File

@ -10,7 +10,7 @@ let rec f tag msg =
f tag msg
let _ =
Thread.new (f "A") "hello";
Thread.create (f "A") "hello";
f "B" "world";
exit 0

View File

@ -18,9 +18,9 @@ let read () =
print_int(sync(receive read_ch)); print_newline()
let main () =
Thread.new accu 0;
Thread.new (sender add_ch) 1;
Thread.new (sender sub_ch) 1;
Thread.create accu 0;
Thread.create (sender add_ch) 1;
Thread.create (sender sub_ch) 1;
while true do read() done
let _ = Printexc.catch main ()

View File

@ -22,9 +22,9 @@ let read () =
print_int(sync(receive read_ch)); print_newline()
let main () =
Thread.new accu 0;
Thread.new adder 1;
Thread.new subber 1;
Thread.create accu 0;
Thread.create adder 1;
Thread.create subber 1;
while true do read() done
let _ = Printexc.catch main ()

View File

@ -5,7 +5,7 @@ type 'a buffer_channel = { input: 'a channel; output: 'a channel }
let new_buffer_channel() =
let ic = new_channel() in
let oc = new_channel() in
let buff = Queue.new() in
let buff = Queue.create() in
let rec buffer_process front rear =
match (front, rear) with
([], []) -> buffer_process [sync(receive ic)] []
@ -15,7 +15,7 @@ let new_buffer_channel() =
wrap (send oc hd) (fun () -> buffer_process tl rear)
]
| ([], _) -> buffer_process (List.rev rear) [] in
Thread.new (buffer_process []) [];
Thread.create (buffer_process []) [];
{ input = ic; output = oc }
let buffer_send bc data =
@ -40,7 +40,7 @@ let g () =
print_string (sync(buffer_receive box)); print_newline()
let _ =
Thread.new f ();
Thread.create f ();
g()

View File

@ -21,6 +21,6 @@ let g () =
print_string "g "; print_string res; print_newline()
let _ =
let id = Thread.new f () in
let id = Thread.create f () in
g ();
Thread.join id

View File

@ -1,5 +1,5 @@
let private_data = (Hashtbl.new 17 : (Thread.t, string) Hashtbl.t)
let private_data_lock = Mutex.new()
let private_data = (Hashtbl.create 17 : (Thread.t, string) Hashtbl.t)
let private_data_lock = Mutex.create()
let set_private_data data =
Mutex.lock private_data_lock;
@ -15,10 +15,10 @@ let process id data =
print_newline()
let _ =
let t1 = Thread.new (process 1) "un" in
let t2 = Thread.new (process 2) "deux" in
let t3 = Thread.new (process 3) "trois" in
let t4 = Thread.new (process 4) "quatre" in
let t5 = Thread.new (process 5) "cinq" in
let t1 = Thread.create (process 1) "un" in
let t2 = Thread.create (process 2) "deux" in
let t3 = Thread.create (process 3) "trois" in
let t4 = Thread.create (process 4) "quatre" in
let t5 = Thread.create (process 5) "cinq" in
List.iter Thread.join [t1;t2;t3;t4;t5]

View File

@ -9,8 +9,8 @@ let test msg producer consumer src dst =
let (in_fd, out_fd) = ThreadUnix.pipe() in
let ipipe = Unix.in_channel_of_descr in_fd in
let opipe = Unix.out_channel_of_descr out_fd in
let prod = Thread.new producer (ic, opipe) in
let cons = Thread.new consumer (ipipe, oc) in
let prod = Thread.create producer (ic, opipe) in
let cons = Thread.create consumer (ipipe, oc) in
Thread.join prod;
Thread.join cons;
if ThreadUnix.system ("cmp " ^ src ^ " " ^ dst) = Unix.WEXITED 0

View File

@ -16,13 +16,13 @@ let engine number address =
close_in ic; close_out oc
let main() =
let addresses = Array.new (Array.length Sys.argv - 1) inet_addr_any in
let addresses = Array.create (Array.length Sys.argv - 1) inet_addr_any in
for i = 1 to Array.length Sys.argv - 1 do
addresses.(i - 1) <- (gethostbyname Sys.argv.(i)).h_addr_list.(0)
done;
let processes = Array.new (Array.length addresses) (Thread.self()) in
let processes = Array.create (Array.length addresses) (Thread.self()) in
for i = 0 to Array.length addresses - 1 do
processes.(i) <- Thread.new (engine i) addresses.(i)
processes.(i) <- Thread.create (engine i) addresses.(i)
done;
for i = 0 to Array.length processes - 1 do
Thread.join processes.(i)

View File

@ -31,13 +31,13 @@ let reader_thread (ic, size) =
done
let main() =
Thread.new gc_thread ();
Thread.create gc_thread ();
let (out1, in1) = Unix.pipe() in
Thread.new writer_thread (in1, 4096);
Thread.new reader_thread (out1, 4096);
Thread.create writer_thread (in1, 4096);
Thread.create reader_thread (out1, 4096);
let (out2, in2) = Unix.pipe() in
Thread.new writer_thread (in2, 16);
Thread.new reader_thread (out2, 16);
Thread.create writer_thread (in2, 16);
Thread.create reader_thread (out2, 16);
stdin_thread()
let _ = main()