@@ -440,10 +440,11 @@ function _spawn_set_thrpool(t::Task, tp::Symbol)
440440end
441441
442442"""
443- Threads.@spawn [:default|:interactive] expr
443+ Threads.@spawn [:default|:interactive|:same ] expr
444444
445445Create a [`Task`](@ref) and [`schedule`](@ref) it to run on any available
446- thread in the specified threadpool (`:default` if unspecified). The task is
446+ thread in the specified threadpool: `:default`, `:interactive`, or `:same`
447+ to use the same as the caller. `:default` is used if unspecified. The task is
447448allocated to a thread once one becomes available. To wait for the task to
448449finish, call [`wait`](@ref) on the result of this macro, or call
449450[`fetch`](@ref) to wait and then obtain its return value.
@@ -468,6 +469,9 @@ the variable's value in the current task.
468469!!! compat "Julia 1.9"
469470 A threadpool may be specified as of Julia 1.9.
470471
472+ !!! compat "Julia 1.12"
473+ The same threadpool may be specified as of Julia 1.12.
474+
471475# Examples
472476```julia-repl
473477julia> t() = println("Hello from ", Threads.threadid());
@@ -486,7 +490,7 @@ macro spawn(args...)
486490 ttype, ex = args
487491 if ttype isa QuoteNode
488492 ttype = ttype. value
489- if ttype != = :interactive && ttype != = :default
493+ if ! in ( ttype, ( :interactive , :default , :same ))
490494 throw (ArgumentError (LazyString (" unsupported threadpool in @spawn: " , ttype)))
491495 end
492496 tp = QuoteNode (ttype)
@@ -507,7 +511,11 @@ macro spawn(args...)
507511 let $ (letargs... )
508512 local task = Task ($ thunk)
509513 task. sticky = false
510- _spawn_set_thrpool (task, $ (esc (tp)))
514+ local tp = $ (esc (tp))
515+ if tp == :same
516+ tp = Threads. threadpool ()
517+ end
518+ _spawn_set_thrpool (task, tp)
511519 if $ (Expr (:islocal , var))
512520 put! ($ var, task)
513521 end
0 commit comments