Futurism lib (futures in D)
Kevin Bealer
kevinbealer at gmail.com
Mon Jan 22 10:38:35 PST 2007
== Quote from Daniel Keep (daniel.keep+lists at gmail.com)'s article
> Kevin Bealer wrote:
...
> > 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.
By the way, I've done this part -- I wrote a function called make_future,
(can't use "future" since thats the module name) and modified the templates
in future.d to store the argument tuples.
There is still things I'm not sure about:
1. Why is a foreach() loop needed to copy a tuple value to another tuple of
the same type?
2. You can't pass a char[10] (for example) to a function that uses a char[]
input -- instead, you need to ask for the slice, for example, using
syntax like:
make_future(& work, 1234, "some string"[]);
^^
I could probably fix this if I knew how to use static if or "is" to find
out whether something is a static array or not. For now, the above syntax
is a not-too-painful workaround.
Kevin
More information about the Digitalmars-d-announce
mailing list