Skip to content

Commit 2075371

Browse files
committed
Sch: Fix dequeue code in processor runner
1 parent 9016977 commit 2075371

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/sch/Sch.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,19 +1105,23 @@ function start_processor_runner!(istate::ProcessorInternalState, uid::UInt64, re
11051105
proc_occupancy = istate.proc_occupancy
11061106
time_pressure = istate.time_pressure
11071107

1108+
work_to_do = false
11081109
while isopen(return_queue)
11091110
# Wait for new tasks
1110-
@dagdebug nothing :processor "Waiting for tasks"
1111-
timespan_start(ctx, :proc_run_wait, to_proc, nothing)
1112-
wait(istate.reschedule)
1113-
@static if VERSION >= v"1.9"
1114-
reset(istate.reschedule)
1111+
if !work_to_do
1112+
@dagdebug nothing :processor "Waiting for tasks"
1113+
timespan_start(ctx, :proc_run_wait, to_proc, nothing)
1114+
wait(istate.reschedule)
1115+
@static if VERSION >= v"1.9"
1116+
reset(istate.reschedule)
1117+
end
1118+
timespan_finish(ctx, :proc_run_wait, to_proc, nothing)
11151119
end
1116-
timespan_finish(ctx, :proc_run_wait, to_proc, nothing)
11171120

11181121
# Fetch a new task to execute
11191122
@dagdebug nothing :processor "Trying to dequeue"
11201123
timespan_start(ctx, :proc_run_fetch, to_proc, nothing)
1124+
work_to_do = false
11211125
task_and_occupancy = lock(istate.queue) do queue
11221126
# Only steal if there are multiple queued tasks, to prevent
11231127
# ping-pong of tasks between empty queues
@@ -1130,7 +1134,9 @@ function start_processor_runner!(istate::ProcessorInternalState, uid::UInt64, re
11301134
@dagdebug nothing :processor "Insufficient occupancy" proc_occupancy=proc_occupancy[] task_occupancy=occupancy
11311135
return nothing
11321136
end
1133-
return dequeue_pair!(queue)
1137+
queue_result = dequeue_pair!(queue)
1138+
work_to_do = length(queue) > 0
1139+
return queue_result
11341140
end
11351141
if task_and_occupancy === nothing
11361142
timespan_finish(ctx, :proc_run_fetch, to_proc, nothing)

0 commit comments

Comments
 (0)