I am trying to split the work of working over a list of integers, by multithreading. The following loop is not multithreaded, however if i run my code it calls an out of index.
//dummy values
int t = 2;
int[] list = new int[t] {1,2}
int[] sd = new int[t+1] {1,2,3}
for (int i = 0; i < t; i++)
{
list[i] = new Thread(() => func(sd[i], sd[i+1]));
list[i].Start();
}
When i check the out of index error i see that i has gone up to 2, which shouldnt happen. When i place a breakpoint and go through step by step, my program terminates just fine.
Even when changing the i to an unused character, or when splitting the new Thread and Start into seperate forloops, the same happens.