Skip to content

Commit 28f58e7

Browse files
authored
doc: recommend @spawn over @async (#44667)
1 parent a6187ea commit 28f58e7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

base/task.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ Values can be interpolated into `@async` via `\$`, which copies the value direct
467467
constructed underlying closure. This allows you to insert the _value_ of a variable,
468468
isolating the asynchronous code from changes to the variable's value in the current task.
469469
470+
!!! warning
471+
It is strongly encouraged to favor `Threads.@spawn` over `@async` always **even when no
472+
parallelism is required** especially in publicly distributed libraries. This is
473+
because a use of `@async` disables the migration of the *parent* task across worker
474+
threads in the current implementation of Julia. Thus, seemingly innocent use of
475+
`@async` in a library function can have a large impact on the performance of very
476+
different parts of user applications.
477+
470478
!!! compat "Julia 1.4"
471479
Interpolating values via `\$` is available as of Julia 1.4.
472480
"""

0 commit comments

Comments
 (0)