Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrent read access on an int[] array: Is it safe? Is it fast?

On a quad-core machine, I am considering the parallelization of C#/.NET algorithm which involves having multiple threads reading the small int[] array concurrently. So far, it seems to be working rather well, but I am not sure where it is specified that concurrent reads on an array are thread-safe in .NET. Any pointers?

Then, I am also wondering if this approach is really efficient? Are there situations where you are better off actually duplicating the input data for each thread, so that there isn't any concurrent read, and each array (maybe?) gets the opportunity to be cached near affinity CPU?

Any thoughts on the best practices in respect of multicore CPUs?

like image 358
Joannes Vermorel Avatar asked Feb 17 '09 11:02

Joannes Vermorel


1 Answers

I don't think there's a problem with concurrent reads. It could be problematic if there are concurrent writes, though.

Immutable data is inherently thread-safe.

like image 93
R. Martinho Fernandes Avatar answered Oct 01 '22 00:10

R. Martinho Fernandes