[racket] understanding future/touch

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Jan 25 11:16:57 EST 2011

Did you read the section of the guide on performance? It has one
attempt at an explanation of this. Feedback on whether or not it was
clear would be valuable.

Thanks,
Robby

On Tuesday, January 25, 2011, Eric Tanter <etanter at dcc.uchile.cl> wrote:
> Hi,
>
> I'd like to understand a point about futures.
>
> The doc says:
> "Between a call to future and touch for a given future, the given thunk may run speculatively in parallel to other computations"
>
> (noticing the _may_)
>
> In order to know if it does, and when, I added a write in the future computation.
>
> (let ([f (future (lambda () (write "ok") (any-double? l2)))])
>         (list (any-double? l1)
>               (touch f)))
>
> I am surprised that if I don't call touch, the future computation is never run (at least not in the many many tries I did).
>
> and if I call touch (even in another function [*]), I get the 2x speedup.
>
> So how do you magically determine whether or not to run the thunk in parallel?
>
> Thanks
>
> -- Éric
>
> [*]
>
> (define (foo x)
>   (touch x))
>
> (time (let ([f (future (lambda () (any-double? l2)))])
>         (list (any-double? l1)
>               (foo f))))
> _________________________________________________
>   For list-related administrative tasks:
>   http://lists.racket-lang.org/listinfo/users
>


Posted on the users mailing list.