I have a C # static static method to create an array ( double : s) and therefore parallelized the operation.
Since I create an array before entering the loop, and then not changing it with a link after that, I think that it should be sufficient to lock the array itself when it is updated in a parallel loop.
Is it possible to use lock in the array itself, or can I encounter some performance or deadlock problems with this approach? Is it better to create a separate lock variable to enable locking?
Here is an example code to illustrate:
static double[] CreateArray(int mn, int n) { var localLock = new object();
source share