Futurism lib (futures in D)

Daniel Keep daniel.keep+lists at gmail.com
Sun Jan 21 06:57:27 PST 2007


Kevin Bealer wrote:
> I posted my future implementation dsource.org.  It's called "Futurism".  Here
> is a simple example of using it:
> 
> int main()
> {
>     // Create a pool of 5 threads
>     ThreadPool P = new ThreadPool(5);
>     scope(exit) P.stop;
> 
>     alias Future!(char[]) FVec;
> 
>     char[] a = args[1], b = args[2], c = args[3];
> 
>     // Starting reading two files at once:
>     FVec f1 = new FVec({ return cast(char[]) read(a); });
>     FVec f2 = new FVec({ return cast(char[]) read(b); });
> 
> 
> 
>     int total_length = f1.value.length + f2.value.length;
> 
>     writefln("total length is %s", f1.value.length + );
> 
>     return 0;
> }
> 

Looks good; more sophisticated than my own.  A few initial thoughts:

1) Have you considered stealing my code and using the "future(...)" 
syntax I used?  It seems a bit cleaner than having to alias the class, 
and then instantiating objects.

2) You say that ThreadPools must be stopped before being deleted.  Maybe 
it would be good to have a ThreadPoolScope class that must be scoped, 
and will call stop for you.

3) Speaking of the thread pools, have you considered creating a default 
pool with (number of hardware threads) threads?  I think std.cpuid can 
give you those numbers, but I don't know enough to say whether it would 
a good idea performance-wise.

Again, it looks really good.  Might have to start using it myself :)

	-- Daniel



More information about the Digitalmars-d-announce mailing list