Futurism lib (futures in D)
Kevin Bealer
kevinbealer at gmail.com
Sun Jan 21 06:29:23 PST 2007
Sorry - the last post got posted early due to an errant keystroke. The code
should look like this:
> 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); });
>
> // You can do other stuff here if you like
> writefln("files are being read");
>
> // This line will wait for both files to be read.
> int total_length = f1.value.length + f2.value.length;
> writefln("total length is %s", f1.value.length + );
>
> return 0;
> }
It took me a bit longer than I expected, when I accidentally did this:
dmd -of~/somefile ...
And ended up with directory called "~". Naturally I did "rm -rvf ~".
There wasn't much else in my home directory right now (new computer), but I was
able to recover the source for this stuff using "strings < /dev/hda5" and some
elaborate "grep" commands.
Try it out if you like, let me know if it has bugs or missing features.
Thanks,
Kevin
More information about the Digitalmars-d-announce
mailing list