diff --git a/base/task.jl b/base/task.jl index bc20ff8ac320a..7e7e5dfc3076b 100644 --- a/base/task.jl +++ b/base/task.jl @@ -1201,30 +1201,19 @@ function wait() process_events() # get the next task to run - result = nothing - have_result = false W = workqueue_for(Threads.threadid()) task = trypoptask(W) - if !(task isa Task) + 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 - result = yieldto(sched_task) - have_result = true - else - task = ccall(:jl_task_get_next, Ref{Task}, (Any, Any, Any), - trypoptask, W, checktaskempty) + return yieldto(sched_task) end + task = ccall(:jl_task_get_next, Ref{Task}, (Any, Any, Any), trypoptask, W, checktaskempty) end - # We may have already switched tasks (via the scheduler task), so - # only switch if we haven't. - if !have_result - @assert task isa Task - set_next_task(task) - result = try_yieldto(ensure_rescheduled) - end - return result + set_next_task(task) + return try_yieldto(ensure_rescheduled) end if Sys.iswindows()