From 9232b7be439afcbd074e102c8e83c9b2dabb48b0 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 14 Jun 2024 21:08:31 -0400 Subject: [PATCH] add sticky task warning to `@task` and `schedule` --- base/docs/basedocs.jl | 3 ++- base/task.jl | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/base/docs/basedocs.jl b/base/docs/basedocs.jl index 0ae04c147a227..d3ab36cf898da 100644 --- a/base/docs/basedocs.jl +++ b/base/docs/basedocs.jl @@ -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 diff --git a/base/task.jl b/base/task.jl index 9ae0de5f94446..cd06f0acd7f7d 100644 --- a/base/task.jl +++ b/base/task.jl @@ -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); @@ -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);