Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @spawn_or_run_task with interactive threads #3385

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
bkamins marked this conversation as resolved.
Show resolved Hide resolved
Base.replace_linenums!(thunk, __source__)
nalimilan marked this conversation as resolved.
Show resolved Hide resolved
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
Loading