title: Semaphore.WaitOne() never returns true, despire avaiablilities
body: <p>I'm working with a semaphore and threading to try to manage chunk loading for a voxel game I'm working on. My general set up, is I have a queue manager job that creates a semaphore and child jobs that wait on it. I've followed all the examples I can, but I cannot figure out why when I am calling WaitOne() on my semaphore in my child jobs, the code never continues for any thread except the main one.</p>
  
  <p>CODE:
  Here is the constructor for the Queue manager job:</p>
  
  <pre><code>  /// &lt;summary&gt;
    /// Create a new job, linked to the level
    /// &lt;/summary&gt;
    /// &lt;param name="level"&gt;&lt;/param&gt;
    protected QueueManagerJob(int maxChildJobsCount = 10) {
      queue = new List&lt;QueueObjectType&gt;();
      runningChildJobs = new Dictionary&lt;QueueObjectType, IThreadedJob&gt;();
      childJobResourcePool = new Semaphore(maxChildJobsCount, maxChildJobsCount);
    }
  </code></pre>
  
  <p>This is the function that the queue manager job runs on it's queue:</p>
  
  <pre><code>  /// &lt;summary&gt;
    /// The threaded function to run
    /// &lt;/summary&gt;
    protected override void jobFunction() {
      // This job will continue until all queue'd chunks are loaded
      while (queue.Count &gt; 0) {
        queue.RemoveAll((queueObject) =&gt; {
          // if the chunk is already being loaded by a job
          if (runningChildJobs.ContainsKey(queueObject)) {
            IThreadedJob chunkLoaderJob = runningChildJobs[queueObject];
  
            // if it's done, remove it from the running jobs and remove it from the queue
            if (chunkLoaderJob.isDone) {
              runningChildJobs.Remove(queueObject);
              return true;
            }
  
            // if it's not done yet, don't remove it
            return false;
            // if it's not being loaded yet by a job, and we have an open spot for a new job, start and add it
          } else {
            IThreadedJob chunkLoaderJob = getChildJob(queueObject);
            runningChildJobs[queueObject] = chunkLoaderJob;
            runningChildJobs[queueObject].start();
  
            // don't remove the running job from the queue yet
            return false;
          }
        });
      }
    }
  </code></pre>
  
  <p>This is the majority of the child job:</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Threaded function, serializes this chunks block data and removes it from the level
      /// &lt;/summary&gt;
      protected override void jobFunction() {
        // wait until we have a resouces, or the job is canceled.
        if (parentResourcePool.WaitOne(-1, isCanceled)) {
          doWork();
  
          parentResourcePool.Release();
          // if the job is canceled, abort after releasing the resource
        } else {
          abort();
        }
      }
    }
  </code></pre>
  
  <p>and that's where it stops running. Each thread stops at</p>
  
  <pre><code>if (parentResourcePool.WaitOne(-1, isCanceled)) {
  </code></pre>
  
  <p>an doesn't seem to continue any further.
  They all end up looking like this in the debugger:</p>
  
  <p><a href="https://i.stack.imgur.com/WHlIY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WHlIY.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/d2gew.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d2gew.png" alt="enter image description here"></a></p>
  
  <p>Also here is a link to my base ThreadedJob class that both of these classes extend:
  <a href="https://github.com/SuperMeip/MarchingCubesCSharp.A1/blob/master/Assets/Scripts/Jobs/ThreadedJob.cs" rel="nofollow noreferrer">https://github.com/SuperMeip/MarchingCubesCSharp.A1/blob/master/Assets/Scripts/Jobs/ThreadedJob.cs</a></p>
  
  <p>just in case the issue may be related to that.</p>