[racket] understanding future/touch

From: Eric Tanter (etanter at dcc.uchile.cl)
Date: Tue Jan 25 11:54:03 EST 2011

Ok, let's give it a try. What I understand is that in my setting:

>> (let ([f (future (lambda () (write "ok") (any-double? l2)))])
>>        (list (any-double? l1)
>>              (touch f)))

the fact that the thunk does a write deactivates parallelism because it is deemed unsafe.

(So, my way of determining whether or not the thunk was run tweaked the whole experiment, by relying on an unsafe operation)

right?

-- Éric


On Jan 25, 2011, at 1:16 PM, Robby Findler wrote:

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