Can static arrays be safely accessed from multiple threads?

delphi, delphi-xe2, multithreading

Solution

Suppose that:

- You have a single instance of an array (static or dynamic), and

- The elements of the array are pure value types (i.e. contain no references), and

- Each thread operates on disjoint sub-arrays, and

- Nothing else in the system writes to the array whilst the threads are operating on it.

With these conditions, which I believe are met by your data structure and threading pattern, then all algorithms are thread-safe.

Problem

If each thread is guaranteed to only read/write to a specific subset of the array can multiple threads work on the same (static) array without resorting to critical sections, etc? EDIT - This is for the specific case of arrays of non-reference-counted types and record/packed-records thereof. If yes, any caveats? My gut feeling is yes but my gut can sometimes be an unreliable source of information.

Original source