[racket] understanding future/touch

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

>> 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).
> 
> How are you testing that it is not run?

the call to (write "ok") above

> If the future needs to do
> something to the global VM state, then it will block and wait to
> resume on the touch, but everything before that will still be done in
> parallel.

so with Jay's additional info, I infer that the future is indeed started in parallel as soon as it is defined, then reaches the (write "ok"), deemed unsafe, put to wait until the touch, if any.

-- Éric

PS: btw, this explanation answers the question of whether or not "the thunk is safe" is determined dynamically, step-by-step, not through an analysis of the code. Right?

Posted on the users mailing list.