Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a Base.root_task method and document it #35726

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ export
# tasks and conditions
Condition,
current_task,
root_task,
isroottask,
islocked,
istaskdone,
istaskstarted,
Expand Down
18 changes: 18 additions & 0 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions doc/src/base/parallel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down