NativeQueue<T>.ParallelWriter Dependency Issues [preview-0.1.1]

Testing NativeQueue.ParallelWriter with another bug (already reported) I have encountered another issue when trying to stack jobs with the same queue. When using it without the ParallelWriter (IJob, for example) I can stack two operations without any issue. As soon as converter to the ParallelWriter version (with IJobParallelFor in my case) this error message pops:

InvalidOperationException: The previously scheduled job RepoCode:EnqueueSingle writes to the NativeArray EnqueueSingle.Queue. You must call JobHandle.Complete() on the job RepoCode:EnqueueSingle, before you can write to the NativeArray safely.

I have an isolated cases submitted with case number 1175406.

[ ]'s

Hard to tell from what you wrote but I suspect this is your issue

Job1 {
   Queue = Queue.AsParallelWriter()
}.Schedule();

Job2 {
   Queue = Queue.AsParallelWriter()
}.Schedule(job1handle);

This doesn’t work because AsParallelWriter has a safety check so can’t be called when it’s in use in a job, you need to do it like

parallel = Queue.AsParallelWriter()

Job1 {
   Queue = parallel
}.Schedule();

Job2 {
   Queue = parallel
}.Schedule(job1handle);

or

Job1 {
   Queue = Queue.AsParallelWriter()
};

Job2 {
   Queue = Queue.AsParallelWriter()
}

Job1.Schedule()
Job2.Schedule(job1handle)
4 Likes

Thanks for this @tertle ! I don’t know that and you learn me an useful trick, I was blocked by that many times and the doc or error messages don’t help …

1 Like

Yes, I’m scheduling the previews job before calling AsParallelWriter for the next. Caching the ParallelWriter version or schedule all jobs after will “fix” the issue. Thanks for the tip.

Unfortunately this behaviour differs from other parallel containers, NativeMultiHashMap more specifically, so I wasn’t sure if it’s a bug or limitation.

[ ]'s