On 01/17/2014 01:28 PM, Kelet wrote: > create a Task[2]. Once the Task is created, use the executeInNewThread > function. You can use yieldForce to wait on it.
That's what I thought initially as well but then I realized that it can be even simpler than that:
import std.stdio; import std.parallelism; void main() { // All of these loops can be free-standing functions as well long sum1 = 0; auto loop1 = { foreach (number; 0 .. 100) { sum1 += number; } }; long sum2 = 0; auto loop2 = { foreach (number; 0 .. 100) { sum2 += number; } }; foreach (loop; [ loop1, loop2 ].parallel) { loop(); } writefln("sum1: %s, sum2: %s", sum1, sum2); } Ali