Browse thread
Smart ways to implement worker threads
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Romain Beauxis <toots@r...> |
| Subject: | Re: [Caml-list] Smart ways to implement worker threads |
Le jeudi 15 juillet 2010 22:52:53, Goswin von Brederlow a écrit :
> The main task will only process priority 0 events and bounce between
> main_task and with_checksum while the worker threads process priority 1
> events and do_checksum.
>
> Correct?
I think it should be like this:
let do_checksum buf _ =
let sum = ...
in
reply_request ();
[]
let main () =
let scheduler = Duppy.create ()
in
for i = 1 to num_cores do
Thread.create (Duppy.queue ~priorities=(fun x -> x = 1) scheduler "worker") ();
done;
while (* New checksum need to be computed *) do
Duppy.Task.add scheduler
{ priority = 1; events = [`Timeout 0.]; handler = fun _ -> do_checksum buf; }
done
It seems in your case you do not need finer-grained priority and all the
workers live at the same priority level..
Now, the main thread does not need to be a task..
Romain