Is this guaranteed to be threadsafe/not produce unexpected results?
Interlocked.Increment(ref _arr[i]);
My intuition tells me this is not, i.e. reading the value in _arr[i] is not guaranteed to be 'atomic' with the actual incrementing.
If I am correct in thinking this is wrong, how can I fix this? Thanks.
_arr[i]? This code doesn't read it, it increments it atomically because that's whatInterlocked.Incrementdoes.