Ordered PLINQ ForAll

后端 未结 6 1346
长情又很酷
长情又很酷 2021-01-04 08:09

The msdn documentation about order preservation in PLINQ states the following about ForAll().

  • Result when the source sequence is ordered
6条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 08:27

    Does this mean that ordered execution of the ForAll method is never guaranteed?

    Yes - order is not guaranteed.

    The parallelisation means that the work is allocated to different threads and their separate outputs are then later combined.

    If you need to order the output then don't use PLinq - or add some later step to put the ordering back in.


    Also, if you are accessing objects like a StringBuilder from within the plinq execution, then please ensure that those objects are threadsafe - and also be aware that this thread safety may in fact make the plinq slower than the non-parallel linq.

提交回复
热议问题