in my program the matrix is presented as an jagged array, using multithreading, I count the sum of all elements of a column, and I assign this sum to an element on the main diagonal. Do I need to use a lock(), if each thread works with a separate column?
int[][] matrix = new int[n][];// jagged array
for (int i = 0; i < n; i++)// run thread
{
int f = i;
threads[i] = new Thread(new ThreadStart(() =>
parallelSuma(matrix1,f,1)));
threads[i].Start();
}
private void parallelSuma(int[][] data, int f, int columnPerThread) {
for (int i = f; i <f+columnPerThread; i++)
{
for (int j = 0; j < data.Length; j++)
{
if(i==j)
continue;
data[i][i] += data[j][i];
}
}
}