vb.net - Parallel.ForEach local storage -
I have recently changed to parallel each of the loops. Fearich loop I'm worried about an object declared outside of the loop, but specified during the loop again. Here's the simplified code.
Model Results as Slim Results New List As Model Models (ModelResults) Dim Object as New Object Parallel.ForEach (_modelEngines, Sub (Model) Results = model .Execute If the result IsNot is nothing, then Sync Lock Lock is Nostalgals Models. Added (results) and Sync Lock and if Results = None End Sub)What a possible race with the result object Is the situation? Will something different if I declare results in the loop?
Yes, the condition of a race with the declared variable outside the loop:
Thread 1: Results = Model. The results of the 'Exit' are from the current model of Thread 1 Engine Thread 2: Result = Model The result of 'Exit2' is the current ModelEngine Thread 2 of Thread 2: If the result is not the result then the result is from the current model of Thread 2 Engine Thread 1: If the results are not, the result is' Hangge from the current model of Thread 2 (! )
Just take it in, I do not know if you want to declare it out of the loop anyway.
Comments
Post a Comment