anchor.diff:      S2 = lists:foldl(fun(TaskId, S1) ->
                       send_term_signal_to_task(TaskId, S1)
                   end, S, jc_utils:running_tasks(Stage, SI)),
  -    lists:foldl(fun({TaskId, _Mod}, #state{tasks = Tasks} = S3) ->
  +    gb_sets:fold(fun({TaskId, _Mod}, #state{tasks = Tasks} = S3) ->
                       #task_info{spec = TaskSpec} = jc_utils:task_info(TaskId, Tasks),
                       #task_spec{stage = TaskStage} = TaskSpec,
                       case TaskStage of
  
positive.code:     #task_spec{stage = Stage} = TaskSpec,
      case jc_utils:new_task_permitted_for_stage(P, Stage, SI) of
          false ->
              do_submit_tasks(Mode, Rest, S#state{pending = [{TaskId,
                              Mode}|Pending]}, NFailuresAllowed);
          true ->
              S1 = S#state{pending = Pending -- [{TaskId, Mode}]},
              do_submit_tasks_in(Mode, [TaskId|Rest], S1, NFailuresAllowed)
      end.
  
  
negative.code:                 hosts      = gb_sets:empty()  :: disco_gbset(host()),
                  tasks      = gb_trees:empty() :: disco_gbtree(task_id(), task_info()),
                  data_map   = gb_trees:empty() :: disco_gbtree(input_id(), data_info()),
                  pending    = gb_sets:empty()  :: disco_gbset({task_id(), submit_mode()}),
                  stage_info = gb_trees:empty() :: disco_gbtree(stage_name(), stage_info())}).
  -type state() :: #state{}.
  
  