Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Long Delay in Thread Scheduling

Discussion in 'Editor & General Support' started by MakeCodeNow, Jun 21, 2014.

  1. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    I'm currently converting my occlusion culling routing to support multiple threads. The pattern is a "go wide" model where the main thread adds work to a queue, worker threads pick items from the cue, and the main thread waits until all work is done. Mostly everything is going great, but every so often one of my worker threads is suspended for close to 100 ms (always about that number). This causes a huge stall in the main thread as it has to wait for this one worker to complete. All of my threads are set to highest priority, and I've tried using ThreadPool, different signaling mechanisms, etc all without any improvement. Has anyone run into something like this before? Do you have any recommendations for how I can force my workers to be run more frequently?

    Thanks!
     
  2. Deleted User

    Deleted User

    Guest

    I dont know much about Unity threads yet, but I have had my share of Thread Hell with C#,,
    What you are running into looks like it may be thread locking.

    Make sure, you dont have two threads trying to access the same memory..

    You may have to add some logic to your threads to make them smart enough to detect a thread lock and bail out so another one can take its place.

    Theads are a pain, because they can crash and become unstable with not much explanation.
     
  3. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Nope. When I get the stall there is only one thread with work remaining and it just gets stuck in a background state for 100ms before being allowed to resume and finish the work.
     
  4. Deleted User

    Deleted User

    Guest

    I don't know of all of this applies to unity.
    But it is a very good write up on threading.

    http://www.albahari.com/threading/part2.aspx