简体   繁体   English

并行For循环。 他们等待完成吗?

[英]Parallel For loops. Are they wait for finish?

I have two for loops. 我有两个for循环。 which the second loop must be started after finishing the first loop . 在完成第一个循环后 必须启动第二个循环

So, If I use two Parallel.For() loops, will the second loop runs after the finishing the first loop? 那么,如果我使用两个Parallel.For()循环,第二个循环将在完成第一个循环后运行吗?

Yes. 是。 Parallel.For will not return until all operations have completed. Parallel.For直到所有操作完成后才会返回。

If you run 如果你跑

Parallel.For(0, 5, i => Console.WriteLine("First {0}", i));
Console.WriteLine("First Finished");
Parallel.For(0, 5, i => Console.WriteLine("Second {0}", i));
Console.WriteLine("Second Finished");

The output is 输出是

First 0
First 2
First 1
First 4
First 3
First Finished
Second 0
Second 4
Second 3
Second 2
Second 1
Second Finished

The order of the integers will vary, but second will always come after first. 整数的顺序会有所不同,但第二个顺序总是在第一个之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM