Skip to content

Commit

Permalink
Fix @spawn_or_run_task with interactive threads
Browse files Browse the repository at this point in the history
When Julia ≥ 1.9 is started with `-tX,Y`, by default tasks use the pool
of interactive threads instead of the default pool. Fix this by updating
`spawn_or_run_task` to match the code used by `@spawn` in Julia master.
  • Loading branch information
nalimilan committed Oct 6, 2023
1 parent b51a973 commit edf0798
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/other/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,22 @@ end
Equivalent to `Threads.@spawn` if `threads === true`,
otherwise run `expr` and return a `Task` that returns its value.
"""
macro spawn_or_run_task(threads, expr)
letargs = Base._lift_one_interp!(expr)
macro spawn_or_run_task(threads, ex)
letargs = Base._lift_one_interp!(ex)

thunk = esc(:(()->($expr)))
thunk = :(()->($(esc(ex))))
@static if VERSION >= v"1.10.0-DEV"

Check warning on line 228 in src/other/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/other/utils.jl#L228

Added line #L228 was not covered by tests
Base.replace_linenums!(thunk, __source__)
end
var = esc(Base.sync_varname)
quote
let $(letargs...)
if $(esc(threads))
local task = Task($thunk)
task.sticky = false
if VERSION >= v"1.9.0"
Base.Threads._spawn_set_thrpool(task, :default)
end
else
# Run expr immediately
res = $thunk()
Expand Down

0 comments on commit edf0798

Please sign in to comment.