一、D如何创建并行foreach(底层逻辑)?
int main(string[] args)
{
int[] arr;
arr.length = 100000000;
/* Why it is working?, it's simple foreach which working with
reference to int from arr, parallel function return ParallelForeach!R
(ParallelForeach!int[]), but I don't know what it is.
Parallel function is part od phobos library, not D builtin function, then what
kind of magic is used for this? */
foreach (ref e;parallel(arr))
{
e = 100;
}
foreach (ref e;parallel(arr))
{
e *= e;
}
return 0;
}
其次,为什么它比简单的 foreach 慢?最后,如果我创建自己的 taskPool(并且不使用全局 taskPool 对象),程序永远不会结束。为什么?