Search Unity

job queue

Discussion in 'General Discussion' started by goldbug, Mar 19, 2014.

  1. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    One of the bullet points for unity 5 is "job queues",

    Does anyone have any info about this? Would it allow me to submit a job from a background thread to the UI thread for example?
     
  2. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    I am very curious about this, because what I've heard is that Unity 'automagically' handles it... And I'd like to know more, and I'd like to have at least some control myself :)
     
  3. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,367
    I would also like to know more about the multithreaded job system too! Which parts of the engine will it affect, how it will work? Please some unity folk stop by, don't let us die dry! :D
    Awesomeness!!! :rolleyes:
     
  4. Alex Korova

    Alex Korova

    Joined:
    Jan 3, 2013
    Posts:
    8
    I'd also like to know more, how does this work and which areas are affected? (PhysX 3.3 is multithreaded, but what more? And is that related to this 'job queue'?)
     
  5. Astfgl

    Astfgl

    Joined:
    Jan 19, 2014
    Posts:
    86
    I expect it will work in a similar fashion to Coroutines, i.e. you define a bunch of short tasks that you want to run in the background, fire them off to Unity's job queue, and then Unity handles all the scheduling and data synchronization and all the other ugly parts that come with multithreaded programming.

    See the Quartz.NET library for an example of how it would look.
     
  6. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,367
    To the look of the videos it looks pretty much like that. At least telling Unity "I need this to run in the background with this priority" would be more than awesome. Or a bit more advanced like distributing a task over different threads (why not). At least I know it'll be running on a different thread that the main thread which is all I need.
     
  7. Aram-Azhari

    Aram-Azhari

    Joined:
    Nov 18, 2009
    Posts:
    142
    Has anyone tried this on the Unity 5 closed beta? If so, could you please elaborate?
     
  8. dilepoutee

    dilepoutee

    Joined:
    Aug 22, 2014
    Posts:
    10
    Ya how is unity5?? want reviews please..
     
  9. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    The only thing I've worked with that I've seen (so far) that uses what is called "JobProcess.exe"
    is baking light maps. There may be one or two of these running at a time, but all 8 cores of my CPU are running.
    Of course, it runs the settings you designate.

    (info from my experience in Unity 5 (closed) beta)
     
  10. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    I think people are reading too much into that headline (and the wording is not the best). What it means is that internally more stuff is multithreaded now (culling, navmesh, ...). Nothing to do with your own script code, though I think folks are looking into how to expose that to scripts (but not in 5.0).
     
  11. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
    It hasn't even released yet...
     
  12. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Review: it's really cool!

    :)
     
  13. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    Also, note that with a job system there usually is no task-dedicated threads like a 'UI thread' and so on - it's more of a threadpool style system.
     
  14. Aram-Azhari

    Aram-Azhari

    Joined:
    Nov 18, 2009
    Posts:
    142
    Why not expose a similar approach for scripts?

    All i want to is:
    Updating transform positions/rotations of 5000 object in a multiithreaded manner. and by that i mean the loop that updates them one by one is located in update() and i find it ridiculous to see the lag happens in this simple task.

    I know what you may think, 5000 is not a large number. Well it is a huge number, if your positions are being read from a Vector3[5000] array. It is not a calculation, but it is actually a memory bound problem where if chunks of that array is updated in parallel, it would drastically increase the speed.


    now if there was a way to pass the objects to unity internal and let it be done in a thread pool, that would have been great.

    This is a realistic simulation that we're talking about and accuracy is everything to us.

    I have been working with my team to accquire unity 5 licenses and we actually were hoping this would be available. but if this is not even intended, then I think Aras is right and the wording has put us and many others in a technical misunderstanding.

    But thank you for the clarification.
     
  15. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Because nothing happens by itself, someone needs to do it :) Some folks here are thinking about how to expose that, but nothing that we "can ship" yet.
     
  16. realghetto

    realghetto

    Joined:
    Jan 21, 2014
    Posts:
    112
    I'm pretty sure it's not, but if it is... BACK TO VOXEL WORLDS I GO, with goldbug.
     
  17. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    How about creating a new YieldInstruction, that I can flag as complete from a background thread, so a ui coroutine can yield waiting for a background thread.
     
  18. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    Letting us create and control our own UnityEngine.AsyncOperation instances would be perfect for this, and useful for quite a few things, I think...
     
    StarManta likes this.
  19. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,655
    Wrong kind of 'job', Bhanu3D...
     
    randomperson42 likes this.
  20. realghetto

    realghetto

    Joined:
    Jan 21, 2014
    Posts:
    112
    yes please
     
  21. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    Here is another idea:

    Code (CSharp):
    1. private int MyBgFunc()
    2. {
    3.      // this gets executed in a background thread
    4.      Thread.sleep(10);
    5.      return 10;
    6. }
    7.  
    8.  
    9. private IEnumerator MyCoroutine()
    10. {
    11.       // this starts a new thread
    12.       var unitythread = StartThread(MyBgFunc);
    13.       yield return unitythread; // this yields until the thread is done
    14.    
    15.       Debug.Log("The tread result was " + unitythread.result);
    16. }
    So StartThread would look similar to StartCoroutine, and returns a yieldinstruction, once the thread finishes, the yieldinstruction is marked complete.

    Even something this simple would be immensely useful for those of us making procedural terrain and other heavy background math.
     
  22. realghetto

    realghetto

    Joined:
    Jan 21, 2014
    Posts:
    112
    wtf? is this guy really applying for a job in a job queue thread about multi-threading? I guess if you are that guy, watching this video goes a long way:
     
  23. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    It's probably fair to say his native tongue is not English.
     
  24. realghetto

    realghetto

    Joined:
    Jan 21, 2014
    Posts:
    112
    Fair enough, true story. I didn't mean to offend anyone.
     
    Don-Gray likes this.
  25. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    I wasn't offended, just thought I'd defend him a little.

    :)