Skip to content

Commit

Permalink
:same -> :samepool
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Jan 21, 2025
1 parent 2d13fde commit ff909c1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ New language features
- actual running time for the task (`Base.Experimental.task_running_time_ns`), and
- wall-time for the task (`Base.Experimental.task_wall_time_ns`).
- Support for Unicode 16 ([#56925]).
- `Threads.@spawn` now takes a `:same` argument to specify the same threadpool as the caller.
`Threads.@spawn :same foo()` which is shorthand for `Threads.@spawn Threads.threadpool() foo()` ([#57109])
- `Threads.@spawn` now takes a `:samepool` argument to specify the same threadpool as the caller.
`Threads.@spawn :samepool foo()` which is shorthand for `Threads.@spawn Threads.threadpool() foo()` ([#57109])

Language changes
----------------
Expand Down
8 changes: 4 additions & 4 deletions base/threadingconstructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ function _spawn_set_thrpool(t::Task, tp::Symbol)
end

"""
Threads.@spawn [:default|:interactive|:same] expr
Threads.@spawn [:default|:interactive|:samepool] expr
Create a [`Task`](@ref) and [`schedule`](@ref) it to run on any available
thread in the specified threadpool: `:default`, `:interactive`, or `:same`
thread in the specified threadpool: `:default`, `:interactive`, or `:samepool`
to use the same as the caller. `:default` is used if unspecified. The task is
allocated to a thread once one becomes available. To wait for the task to
finish, call [`wait`](@ref) on the result of this macro, or call
Expand Down Expand Up @@ -490,7 +490,7 @@ macro spawn(args...)
ttype, ex = args
if ttype isa QuoteNode
ttype = ttype.value
if !in(ttype, (:interactive, :default, :same))
if !in(ttype, (:interactive, :default, :samepool))
throw(ArgumentError(LazyString("unsupported threadpool in @spawn: ", ttype)))
end
tp = QuoteNode(ttype)
Expand All @@ -512,7 +512,7 @@ macro spawn(args...)
local task = Task($thunk)
task.sticky = false
local tp = $(esc(tp))
if tp == :same
if tp == :samepool
tp = Threads.threadpool()
end
_spawn_set_thrpool(task, tp)
Expand Down
6 changes: 3 additions & 3 deletions test/threadpool_use.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ using Base.Threads
@test fetch(Threads.@spawn Threads.threadpool()) === :default
@test fetch(Threads.@spawn :default Threads.threadpool()) === :default
@test fetch(Threads.@spawn :interactive Threads.threadpool()) === :interactive
@test fetch(Threads.@spawn :same Threads.threadpool()) === Threads.threadpool()
@test fetch(Threads.@spawn :samepool Threads.threadpool()) === Threads.threadpool()
@sync for tp in [:interactive, :default]
Threads.@spawn tp begin
@test fetch(Threads.@spawn :same Threads.threadpool()) === Threads.threadpool()
@test fetch(Threads.@spawn :samepool Threads.threadpool()) === Threads.threadpool()
end
end
wait(Threads.@spawn :interactive begin
@test fetch(Threads.@spawn :same Threads.threadpool()) === Threads.threadpool()
@test fetch(Threads.@spawn :samepool Threads.threadpool()) === Threads.threadpool()
end)
tp = :default
@test fetch(Threads.@spawn tp Threads.threadpool()) === :default
Expand Down

0 comments on commit ff909c1

Please sign in to comment.