concurrency
downs
default_357-line at yahoo.de
Mon Feb 4 09:00:56 PST 2008
Jason House wrote:
> Sean Kelly Wrote:
>
>> Bedros Hanounik wrote:
>>> I think the best way to tackle concurrency is to have two types of functions
>>>
>>> blocking functions (like in the old sequential code execution)
>>>
>>> and non-blocking functions (the new parallel code execution)
>>>
>>> for non-blocking functions, the function returns additional type which is true when function execution is completed
>> This is basically how futures work. It's a pretty useful approach.
>>
>>
>> Sean
>
>
> 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. :)
scrapple.tools' ThreadPool class has a futures implementation.
Here's an example:
auto t = new Threadpool(2);
auto f = t.future(&do_complicated_calculation);
auto g = t.future(&do_complicated_calculation2);
return f() + g();
--downs
More information about the Digitalmars-d
mailing list