concurrency
downs
default_357-line at yahoo.de
Mon Feb 4 11:12:36 PST 2008
Joel C. Salomon wrote:
> downs wrote:
>> Jason House wrote:
>>> I've never heard of that. Does anyone have a good link for extra detail on futures?
>>>
>> Basically, it comes down to a function that takes a delegate dg, and runs it on a threadpool, returning a wrapper object.
>> The wrapper object can be evaluated, in which case it blocks until the original dg has returned a value. This value is then returned by the wrapper, as well as cached.
>> The idea is that you create a future for a value that you know you'll need soon, then do some other task and query it later. :)
>
> & while Sean Kelly wrote:
>> Futures are basically Herb Sutter's rehashing of Hoare's CSP model.
>
> More specifically, this sounds like a special case of a CSP-like channel
> where only one datum is ever transmitted. (Generally, channels are
> comparable to UNIX pipes and can transmit many data.)
>
Heh.
Funny coincidence.
Let's take a look at the implementation of Future(T):
class Future(T) {
T res; bool done;
MessageChannel!(T) channel;
this() { New(channel); }
T eval() { if (!done) { res=channel.get(); done=true; } return res; }
alias eval opCall;
bool finished() { return channel.canGet; }
}
:)
--downs
More information about the Digitalmars-d
mailing list