Quick answer: Mark [ReadOnly] on shared NativeArray fields in each job. Jobs run in parallel.
Two analysis jobs read the same dataset. Profiler shows them running serially. Without ReadOnly, scheduler enforces ordering.
The Fix
[BurstCompile]
struct JobA : IJob {
[ReadOnly] public NativeArray<float> SharedData;
public NativeArray<float> OutA;
public void Execute() { /* read */ }
}
[BurstCompile]
struct JobB : IJob {
[ReadOnly] public NativeArray<float> SharedData; // same array
public NativeArray<float> OutB;
public void Execute() { /* read */ }
}
// Schedule both in parallel
var hA = jobA.Schedule();
var hB = jobB.Schedule(); // not dependent on hA
JobHandle.CompleteAll(ref hA, ref hB);
ReadOnly tells the safety system multiple readers are fine. Without it: serial.
Verifying
Profiler: jobA and jobB on different worker threads simultaneously. Without ReadOnly: sequential.
“ReadOnly. Parallel reads.”
Related Issues
For NativeList resize, see resize. For ReadOnly write error, see readonly write.
ReadOnly. Parallel reads.