Search Unity

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

Discussion in 'Entity Component System' started by elcionap, Aug 9, 2019.

  1. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
    Testing NativeQueue<T>.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
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Hard to tell from what you wrote but I suspect this is your issue

    Code (CSharp):
    1. Job1 {
    2.    Queue = Queue.AsParallelWriter()
    3. }.Schedule();
    4.  
    5. Job2 {
    6.    Queue = Queue.AsParallelWriter()
    7. }.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

    Code (CSharp):
    1.  
    2. parallel = Queue.AsParallelWriter()
    3.  
    4. Job1 {
    5.    Queue = parallel
    6. }.Schedule();
    7.  
    8. Job2 {
    9.    Queue = parallel
    10. }.Schedule(job1handle);
    or

    Code (CSharp):
    1.  
    2. Job1 {
    3.    Queue = Queue.AsParallelWriter()
    4. };
    5.  
    6. Job2 {
    7.    Queue = Queue.AsParallelWriter()
    8. }
    9.  
    10. Job1.Schedule()
    11. Job2.Schedule(job1handle)
     
    Last edited: Aug 9, 2019
    StefanWo, yulcatWorking and elcionap like this.
  3. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    369
    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 ....
     
    tertle likes this.
  4. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
    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