Search Unity

Combining unmanaged (bursted) Jobs and managed Jobs

Discussion in 'Burst' started by Kobix, Oct 7, 2021.

  1. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    146
    Hello, short question, is there problem when combining managed and unmanaged jobs?

    Managed are still IJob but has GCHandle reference.

    What I have is: managed IJobFor that has GCHandle, that spawns jobs: and I want to spawn mix of managed and unmanaged jobs here then wait for all them to complete.

    Is that possible or no? Meaning: will burstable Jobs be actually bursted?

    Thanks!

    p.s.: rationale here is to get multithreaded working ASAP without having to rewrite all my codebase to burstable, since it's huge pain for some parts of code. Little or no allocations done in managed code.
     
  2. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    The job system doesn't really care about what you do in a job. Mixing managed & unmanaged is fine. You can also call burst functions from managed code running in a job. (small side-note; last time I tested the burst function had to do a first-time-run on the mainthread or it throws an error; some dodgy reflection code fixed that for me)
    Just means you lack the safety mechanics and such related to NativeArrays, [ReadOnly], [WriteOnly] etc. It's more like a Task<>.

    I don't think you can spawn a job from a job though.
     
  3. Kobix

    Kobix

    Joined:
    Jan 23, 2014
    Posts:
    146
    Thanks!

    I tried it and it works. I see both managed/unmanaged jobs in Workers.
    Hmm didn't knew jobs can't spawn jobs, makes sense I got errors.