PLINQ delayed execution

Posted by tbischel on Stack Overflow See other posts from Stack Overflow or by tbischel
Published on 2010-03-08T18:49:54Z Indexed on 2010/03/08 18:51 UTC
Read the original article Hit count: 645

Filed under:
|
|
|
|

I'm trying to understand how parallelism might work using PLINQ, given delayed execution. Here is a simple example.

string[] words = { "believe", "receipt", "relief", "field" };
bool result = words.AsParallel().Any(w => w.Contains("ei"));

With LINQ, I would expect the execution to reach the "receipt" value and return true, without executing the query for rest of the values.

If we do this in parallel, the evaluation of "relief" may have began before the result of "receipt" has returned. But once the query knows that "receipt" will cause a true result, will the other threads yield immediately?

In my case, this is important because the "any" test may be very expensive, and I would want to free up the processors for execution of other tasks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about PLINQ