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

Rebase @tspawnat to Base.@spawn for interpolation syntax #16

Closed
wsphillips opened this issue Jul 22, 2020 · 2 comments
Closed

Rebase @tspawnat to Base.@spawn for interpolation syntax #16

wsphillips opened this issue Jul 22, 2020 · 2 comments

Comments

@wsphillips
Copy link

macro tspawnat(thrdid, expr)
thunk = esc(:(()->($expr)))
var = esc(Base.sync_varname)
tid = esc(thrdid)
quote
if $tid < 1 || $tid > Threads.nthreads()
throw(AssertionError("@tspawnat thread assignment ($($tid)) must be between 1 and Threads.nthreads() (1:$(Threads.nthreads()))"))
end
local task = Task($thunk)
task.sticky = false
ccall(:jl_set_task_tid, Cvoid, (Any, Cint), task, $tid-1)
if $(Expr(:isdefined, var))
push!($var, task)
end
schedule(task)
task
end
end

Could the interpolation syntax support present in Threads.@spawn be added here? Looks like it could be done fairly easily with a bit of copy-paste:

https://github.com/JuliaLang/julia/blob/02990278b31515a4212c2f5cbfe123661f2e26f2/base/threadingconstructs.jl#L166-L182

@wsphillips wsphillips changed the title Rebase to to Base.@spawn for interpolation syntax Rebase @tspawnat to Base.@spawn for interpolation syntax Jul 22, 2020
@tro3
Copy link
Owner

tro3 commented Jul 23, 2020

Interesting - I bet the Base.@spawn code got updated past v1.3, because at the time, the 1.3 code was mimicked as closely as possible. I'll check to see if an update here would break 1.3 compatibility, but otherwise this is a no-brainer.

@wsphillips
Copy link
Author

It might, actually. I'm not sure if Base._lift_one_interp! was available in v1.3. I tested on v1.4.2. If it's indeed breaking for v1.3 could a reasonable workaround be to wrap the definitions in a conditional checking Julia's version? e.g. if Julia >1.4 use interpolated version, else existing? That ought to make the upgrade transparent and consistent with the functionality of @spawn by Julia version

@tro3 tro3 closed this as completed in bd32983 Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants