関数型言語ML(SML, OCaml, etc.), Part 4
■ このスレッドは過去ログ倉庫に格納されています
0259デフォルトの名無しさん
2006/02/20(月) 16:51:08exactly. ちなみに、共有リソースはこんな感じで。
open Event
type 'a mvar = { takeCh : 'a channel; putCh : 'a channel; ackCh : bool channel }
exception Put
let mVar () =
let takeCh = new_channel () and putCh = new_channel () and ackCh = new_channel () in
let rec empty () =
let x = sync (receive putCh) in
sync (send ackCh true);
full x
and full x =
select [
wrap (send takeCh x) empty;
wrap (receive putCh) (fun _ -> sync (send ackCh false); full x)
]
in
ignore(Thread.create empty ());
{ takeCh = takeCh; putCh = putCh; ackCh = ackCh }
let take { takeCh = takeCh } = receive takeCh
let put { putCh = putCh; ackCh = ackCh } x =
sync (send putCh x);
if sync (receive ackCh) then ()
else raise Put
■ このスレッドは過去ログ倉庫に格納されています