関数型言語ML(SML, OCaml, etc.), Part 4
■ このスレッドは過去ログ倉庫に格納されています
0274271
2006/03/02(木) 20:07:55let getCh = new_channel () in
let putCh = new_channel () in
let rec loop_ex fix x =
select [
wrap (send getCh fix) (fun () -> loop_ex fix x);
wrap (receive putCh) (loop_ex fix)
] in
let rec loop x =
select [
wrap (send getCh x) (fun () -> loop x);
wrap (receive putCh) (fun fix-> loop_ex fix fix)
] in
ignore (Thread.create loop x);
{ getCh = getCh; putCh = putCh }
let _ =
let c = cell 10 in
Printf.printf "v=%d\n" (get c) ;
put c 20;
Printf.printf "v=%d\n" (get c) ;
put c 10;
Printf.printf "v=%d\n" (get c) ;
一応、結果は10,20,20と出る
>>273
よくわからないけれど正解なんだろうね・・・
数学ワカンネ
■ このスレッドは過去ログ倉庫に格納されています