एक और (काँटेदार) की प्रक्रिया में एक मूल्य के लिए एक समारोह लागू करने के लिए निम्नलिखित invoke
Combinator का प्रयोग करें और फिर जब ()
मूल्य लागू किया जाता है उसके परिणाम के लिए इंतजार ब्लॉक:
let invoke (f : 'a -> 'b) x : unit -> 'b =
let input, output = Unix.pipe() in
match Unix.fork() with
| -1 -> (let v = f x in fun() -> v)
| 0 ->
Unix.close input;
let output = Unix.out_channel_of_descr output in
Marshal.to_channel output (try `Res(f x) with e -> `Exn e) [];
close_out output;
exit 0
| pid ->
Unix.close output;
let input = Unix.in_channel_of_descr input in
fun() ->
let v = Marshal.from_channel input in
ignore (Unix.waitpid [] pid);
close_in input;
match v with
| `Res x -> x
| `Exn e -> raise e
स्रोत
2009-10-18 22:19:10
ocaml4multicore उपलब्ध है (सीमाओं के साथ), देखें: http://www.algo-prog.info/ocmc/web/ – nlucaroni