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

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


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.


In your case, concurrent reads over your array will be thread safe.

As for your algorithms effectiveness, depending on the size of your array, if it will fit in the cache then you may see excellent performance gains, as the multicores effectively "fight" for cache in the CPU. If they are fighting to fill the cache with the same information, they will share meaning more cache hits and better performance.

Assuming that your array fits into the cache...


There is no reason not read the content of an array concurrently assuming that is content will never change. There is no concurrency issue hence no need to copy.

I doubt there is much you can do to make it faster either.