All about Async/Await, System.Threading.Tasks, System.Collections.Concurrent, System.Linq, and more…
If you've played around with PLINQ and Parallel.ForEach loops in .NET 4, you may have noticed that many PLINQ queries can be rewritten as parallel loops, and also many parallel loops can be rewritten as PLINQ queries. However, both parallel loops and PLINQ have distinct advantages in different situations. When writing parallel code, it helps to understand these differences to appropriately decide between the two models.
Pamela Vagata wrote an interesting comparison of parallel loops and PLINQ: When Should I Use Parallel.ForEach? When Should I Use PLINQ?
IMHO last sample FindLowestIndex<T,T> is wrong. There is no synchronization so it can happen that matchedindex will not be lowest. It is needed rewrite it to use ParallelLoopState.LowestBreakIteration.
Great catch! The lack of synchronization on matchedIndex can result in a race condition such that the returned value isn't the lowest index. Thanks for pointing this error out, we're looking into fixing this in the paper :)
The like "When Should I Use Parallel.ForEach? When Should I Use PLINQ?" is broken
The link "When Should I Use Parallel.ForEach? When Should I Use PLINQ?" is broken
@PepLamb: Thanks. Fixed.