anchor.diff:      Job.Proc := aProc;
   
       TMonitor.Enter(fTaskQueue);
  +    try
  +      fWorkCompleted := False;
  +      fTaskQueue.Enqueue(Job);
   
  -    fWorkCompleted := False;
  -    fTaskQueue.Enqueue(Job);
  -
  -    TMonitor.Pulse(fTaskQueue);
  -    TMonitor.Exit(fTaskQueue);
  +      TMonitor.Pulse(fTaskQueue);
  +    finally
  +      TMonitor.Exit(fTaskQueue);
  +    end;
     end;
   end;
   
  
positive.code:     Exit;
  
    TMonitor.Enter(fTaskQueue);
    if not fWorkCompleted and not Finished then
    begin
      if not TMonitor.Wait(fTaskQueue, 10000) then
        raise Exception.Create('Timeout in TKMWorkerThread.WaitForAllWorkToComplete');
    end;
    TMonitor.Exit(fTaskQueue);
  end;
  
  end.
  
negative.code:   while LoopRunning do
    begin
      TMonitor.Enter(fTaskQueue);
      try
        if fTaskQueue.Count > 0 then
        begin
          Job := fTaskQueue.Dequeue;
        end
        else
        begin
          //We may only terminate once we have finished all our work
          if Terminated then
          begin
            LoopRunning := False;
          end
          else
          begin
            //Notify main thread that worker is idle if it's blocked in WaitForAllWorkToComplete
            fWorkCompleted := True;
            TMonitor.Pulse(fTaskQueue);
  
            TMonitor.Wait(fTaskQueue, 10000);
            if fTaskQueue.Count > 0 then
              Job := fTaskQueue.Dequeue;
          end;
        end;
      finally
        TMonitor.Exit(fTaskQueue);
      end;
  
      if Job <> nil then
      begin
  