Full closures for D

torhu no at spam.invalid
Mon Nov 5 20:31:25 PST 2007


Mikola Lysenko wrote:
> I'm excited.  For the first time it is now possible to do futures in 7 lines of code:
> 
> T delegate() future(T)(lazy T expr)
> {
>     T res;
>     auto t = new Thread({res = expr();});
>     t.start;
>     return { t.wait; return res; }
> }
> 
> 
> Which could then be used as follows:
> 
> auto hard_result = future( hard_expression );
> 
> // Do stuff ...
> 
> use_result(hard_result());

I tested your code and got this:

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION(0xc0000005) at (0x00930f80)
->us
#0 ?? ()
#1 0x00405191 in MFZi std.thread.Thread.run () from thread
#2 0x0040fd99 in ___threadstartex at 4 () from threadex
->

Something's wrong, but I'm not sure what. res is correctly put on the 
heap, so it's not that.



More information about the Digitalmars-d mailing list