Skip to content

Commit 645a429

Browse files
add sticky task warning to @task and schedule (#54815)
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.
1 parent 94dff97 commit 645a429

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

base/docs/basedocs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,8 @@ The task will run in the "world age" from the parent at construction when [`sche
17661766
!!! warning
17671767
By default tasks will have the sticky bit set to true `t.sticky`. This models the
17681768
historic default for [`@async`](@ref). Sticky tasks can only be run on the worker thread
1769-
they are first scheduled on. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
1769+
they are first scheduled on, and when scheduled will make the task that they were scheduled
1770+
from sticky. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
17701771
bit manually to `false`.
17711772
17721773
# Examples

base/task.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ end
115115
Wrap an expression in a [`Task`](@ref) without executing it, and return the [`Task`](@ref). This only
116116
creates a task, and does not run it.
117117
118+
!!! warning
119+
By default tasks will have the sticky bit set to true `t.sticky`. This models the
120+
historic default for [`@async`](@ref). Sticky tasks can only be run on the worker thread
121+
they are first scheduled on, and when scheduled will make the task that they were scheduled
122+
from sticky. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
123+
bit manually to `false`.
124+
118125
# Examples
119126
```jldoctest
120127
julia> a1() = sum(i for i in 1:1000);
@@ -839,6 +846,13 @@ the woken task.
839846
It is incorrect to use `schedule` on an arbitrary `Task` that has already been started.
840847
See [the API reference](@ref low-level-schedule-wait) for more information.
841848
849+
!!! warning
850+
By default tasks will have the sticky bit set to true `t.sticky`. This models the
851+
historic default for [`@async`](@ref). Sticky tasks can only be run on the worker thread
852+
they are first scheduled on, and when scheduled will make the task that they were scheduled
853+
from sticky. To obtain the behavior of [`Threads.@spawn`](@ref) set the sticky
854+
bit manually to `false`.
855+
842856
# Examples
843857
```jldoctest
844858
julia> a5() = sum(i for i in 1:1000);

0 commit comments

Comments
 (0)