Commit a6724f4e authored by Andreas Pfurtscheller's avatar Andreas Pfurtscheller

Add threading.

parent e678435b
......@@ -39,25 +39,50 @@ end
open Thread
open Event
let cmp_tpl a b = compare (fst a) (fst b)
(* 13.4 *)
let par_unary f a = failwith "TODO"
let par_unary : ('a -> 'b) -> ('a list -> 'b list) = fun f ->
let create_event f el =
let channel = Event.new_channel () in
let _ = Thread.create (fun x -> Event.sync (send channel (f x))) el in
Event.receive channel
in
let create_events l =
List.mapi (fun i el -> Event.wrap (create_event f el) (fun x -> (i,x))) l in
let select_events l =
List.map (fun _ -> Event.select l) l in
fun l ->
let selected = select_events (create_events l) in
List.map snd (List.sort cmp_tpl selected)
let par_binary : ('a -> 'b -> 'c) -> ('a list -> 'b list -> 'c list) = fun f ->
fun l1 l2 ->
let mapper = par_unary (fun (e1,e2) -> f e1 e2) in
mapper (List.map2 (fun e1 e2 -> (e1,e2)) l1 l2)
let par_binary f a b = failwith "TODO"
(* 13.5 *)
exception OutOfBounds
module Array = struct
type 'a t = unit (* todo *)
type 'a t = Tail | Node of 'a * 'a t
type 'a req = GET of int * 'a channel | SET of int * 'a
let make s v =
let rec build s v = match s with
| 0 -> Tail
| _ -> Node (v, (build (s-1) v)) in
let make s v = failwith "TODO"
let size a = failwith "TODO"
let set i v a = failwith "TODO"
let get i a = failwith "TODO"
let get i a = let reply = new_channel ()
in sync (send a )
let resize s v a = failwith "TODO"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment