So I have 3 nested for loops with the inner two doing little work. I want to convert the outer-most loop into a parallel one.
My question is:
If I have a variable inside the loop, something that is used as a temp value holder and takes a new value each loop. Do I need to worry about that variable when the parallelism begins ?
I mean are all the threads gonna be over-writing the same variable ?
for (int i = 0; i < persons.number; i++) //Loop all the people
var Dates = persons[i].Appointments.bydate(DateStep);
Do I need to worry about the Dates variable in the parallel loop ?
Sorry for the bad formatting of my question but it's only my second question and I'm getting there.
In short: No.
Because this variable is scoped inside the loop, it will be reassigned for every iteration of the loop anyways. It is not a value which is shared among different threads.
The only variables which you should worry about are those scoped outside of the loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With