Version française
Home     About     Download     Resources     Contact us    
Browse thread
Smart ways to implement worker threads
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Goswin von Brederlow <goswin-v-b@w...>
Subject: Re: [Caml-list] Smart ways to implement worker threads
Romain Beauxis <toots@rastageeks.org> writes:

> 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.. 

But then how does the main thread notice when a checksum is finished
computing? The information has to flow both ways.

MfG
        Goswin