Hello I have a sample of code but I'm not sure how to lock the variables in Parallel.For, my understanding is that many threads at the same are using the variables used inside the for.
int VVA=0;
for (int i = 0; i < result.Count; i++)
{
if (result[i] == 'a')
va++;
};
//Result with normal for: 5000
Parallel.For(0, result.Count, index =>
{
if (result[index] == 'a')
va++;
Interlocked.Add(ref VVA, va);
});
//Result with parallel for: 43565646 (something like that)
What is missing here? thanks in advance!