Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1145,16 +1145,6 @@ function throwto(t::Task, @nospecialize exc)
return try_yieldto(identity)
end

@inline function wait_forever()
while true
wait()
end
end

const get_sched_task = OncePerThread{Task}() do
Task(wait_forever)
end

function ensure_rescheduled(othertask::Task)
ct = current_task()
W = workqueue_for(Threads.threadid())
Expand Down Expand Up @@ -1204,11 +1194,13 @@ function wait()
W = workqueue_for(Threads.threadid())
task = trypoptask(W)
if task === nothing
# No tasks to run; switch to the scheduler task to run the
# thread sleep logic.
sched_task = get_sched_task()
if ct !== sched_task
return yieldto(sched_task)
# No tasks to run; if the current task is done/failed, switch to an
# empty "scheduler" task to run the thread sleep logic.
if istaskdone(ct)
scheduler_task() = nothing
if ct.code !== scheduler_task
return yieldto(Task(scheduler_task))
end
end
task = ccall(:jl_task_get_next, Ref{Task}, (Any, Any, Any), trypoptask, W, checktaskempty)
end
Expand Down
2 changes: 1 addition & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
ct->queue = jl_nothing;
ct->tls = jl_nothing;
jl_atomic_store_relaxed(&ct->_state, JL_TASK_STATE_RUNNABLE);
ct->start = NULL;
ct->start = jl_nothing;
ct->result = jl_nothing;
ct->donenotify = jl_nothing;
jl_atomic_store_relaxed(&ct->_isexception, 0);
Expand Down