I am trying to implement multithreading in my application, which does a lot of floating point calculations (neural network).
I wrote a function that does the necessary calculations and updates the array outside this function. My actual single-threaded code looks like this (simplified for a better understanding):
class MyClass { // this array after all calculations should contain // result of only one calculation, // that returned smallest value in one of array fields // (smallest neural network error) float[] bestResult; // runs calculations on all "sets of data" public void findBestResult(void) { foreach (something...) // data rows from database cached in one array { calculate(x[]); } } // calculates one "set of data" public void calculateAndUpdateResultIfBetter(float[] inputData) { if (bestResult[0] > calculatedData[0]) bestResult = calculatedData; // update only if condition is true } }
I am a low level programmer, I donβt know how to use advanced (?) .NET streaming methods that use Synchronize, etc. I know how to create one additional thread for something and update some form controls using delegates.
I donβt know how to work with 2-8 threads doing the same and competing with each other.
Question 1 - can you help me? I donβt know where to start. Solved by Niko Draskovic
EDIT: Question 2 - does the lock () method lock my array for reading and writing?
Kamil source share