[racket] Future thread

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Apr 18 16:13:02 EDT 2011

On Mon, Apr 18, 2011 at 2:44 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
> I have a program that spends most of the time waiting for user
> input/time to advance (think of a World.) I have a computation that I
> can perform at Frame 0, but I don't need the result until Frame 10. I
> will do some work between these frames.
>
> I'd like to be able to have this computation take place in the
> background in parallel. I'd create it in frame 0, but delay forcing it
> until frame 10.
>
> Now, if I used a future, then, if the future does something unsafe,
> let's say half way through its execution, then half of the work would
> be blocked until frame 10. So, 50% of the task would be in parallel.
>
> If I used a thread, then nothing would run in parallel, but it would
> run in the background---i.e. utilize the time in between my frames.
> But this would actually compete with the work for frames 1 through 9,
> so they'd run slower.
>
> I'd like the best of both worlds. I would imagine that this would work
> by having blocked futures be a schedule-able thread so that if they
> need to do unsafe work---and no other Racket thread is
> available---then they could be selected for a quanta before being put
> back in the truly parallel world.
>
> Do futures already work like this? The documentation seems to suggest
> not. If not, is this possible?

I believe that this doesn't happen in the current implementation, but
you might also prefer if futures just didn't get stuck on the thing
that you're currently getting stuck on.

That is, futures are designed to set up an incremental path to getting
lots of stuff to run in parallel. Sometimes doing something fancy to
cope with things like the above is necessary but it always is
preferable to just get your tasks to run in parallel.

So, in that spirit, what is causing your tasks to get stuck? (You can
use the debug log to get some information on this.)

Robby


Posted on the users mailing list.