On 27-3-2013 15:17, Jos van Uden wrote:
On 27-3-2013 0:20, bearophile wrote:
This task has just a Tango entry:
http://rosettacode.org/wiki/Concurrent_computing
So I am writing a Phobos version. This seems to work as requested:
import std.stdio, std.random, std.parallelism, core.thread, core.time;
void main() {
foreach (m; ["Enjoy", "Rosetta", "Code"])
task!((s) {
Thread.sleep(uniform(0, 1000).dur!"msecs");
s.writeln;
})(m).executeInNewThread;
}
I have also tried with a parallel foreach, the syntax is cleaner, but to me it
always print the strings in the given order (so it's not doing what the task
requires), do you know why?
import std.stdio, std.random, std.parallelism, core.thread, core.time;
void main() {
foreach (s; ["Enjoy", "Rosetta", "Code"].parallel(1)) {
Thread.sleep(uniform(0, 1000).dur!"msecs"); // Can't use UFCS.
s.writeln;
}
}
(...) my system:
DMD32 D Compiler v2.062
win7 64 bits, i7 2600