diff --git a/base/exports.jl b/base/exports.jl index 12d11601aa034..9453a11824fe0 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -655,6 +655,8 @@ export # tasks and conditions Condition, current_task, + root_task, + isroottask, islocked, istaskdone, istaskstarted, diff --git a/base/task.jl b/base/task.jl index b717a31bdb156..43537bfae10ec 100644 --- a/base/task.jl +++ b/base/task.jl @@ -119,6 +119,24 @@ Get the currently running [`Task`](@ref). """ current_task() = ccall(:jl_get_current_task, Ref{Task}, ()) +""" + root_task() + +Get the initial [`Task`](@ref). Compare to [`current_task`](@ref) above to see +if the current [`Task`](@ref) is the root [`Task`](@ref). This may be important +for interoperability with other languages or native libraries. +""" +root_task() = roottask +# Alternatively, consider exposing :jl_get_root_task + +""" + isroottask(task::Task = current_task()) + +Test if the current or optionally passed [`Task`](@ref) is the root `Task`. +Returns true if the current or given `Task` is the root `Task`. +""" +isroottask(task::Task = current_task()) = Base.roottask === task + """ istaskdone(t::Task) -> Bool diff --git a/doc/src/base/parallel.md b/doc/src/base/parallel.md index 453cd4562ba2c..4a634b55095bd 100644 --- a/doc/src/base/parallel.md +++ b/doc/src/base/parallel.md @@ -9,6 +9,8 @@ Base.asyncmap Base.asyncmap! Base.fetch(t::Task) Base.current_task +Base.root_task +Base.isroottask Base.istaskdone Base.istaskstarted Base.istaskfailed