Skip to content

Commit

Permalink
add sticky task warning to @task and schedule (#54815)
Browse files Browse the repository at this point in the history
The fact that `@async` causes the task that it was scheduled from to
also become sticky is well documented in the warning in [`@async`
docs](https://docs.julialang.org/en/v1/base/parallel/#Base.@async), but
it's not clear that creating a task and scheduling it also has the same
effect, by default.
  • Loading branch information
IanButterworth authored Jun 18, 2024
1 parent c5994e4 commit a9b4869
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,8 @@ The task will run in the "world age" from the parent at construction when [`sche
!!! warning
By default tasks will have the sticky bit set to true `t.sticky`. This models the
historic default for [`@async`](@ref). Sticky tasks can only be run on the worker thread
they are first scheduled on. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
they are first scheduled on, and when scheduled will make the task that they were scheduled
from sticky. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
bit manually to `false`.
# Examples
Expand Down
14 changes: 14 additions & 0 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ end
Wrap an expression in a [`Task`](@ref) without executing it, and return the [`Task`](@ref). This only
creates a task, and does not run it.
!!! warning
By default tasks will have the sticky bit set to true `t.sticky`. This models the
historic default for [`@async`](@ref). Sticky tasks can only be run on the worker thread
they are first scheduled on, and when scheduled will make the task that they were scheduled
from sticky. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
bit manually to `false`.
# Examples
```jldoctest
julia> a1() = sum(i for i in 1:1000);
Expand Down Expand Up @@ -991,6 +998,13 @@ the woken task.
It is incorrect to use `schedule` on an arbitrary `Task` that has already been started.
See [the API reference](@ref low-level-schedule-wait) for more information.
!!! warning
By default tasks will have the sticky bit set to true `t.sticky`. This models the
historic default for [`@async`](@ref). Sticky tasks can only be run on the worker thread
they are first scheduled on, and when scheduled will make the task that they were scheduled
from sticky. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
bit manually to `false`.
# Examples
```jldoctest
julia> a5() = sum(i for i in 1:1000);
Expand Down

0 comments on commit a9b4869

Please sign in to comment.