Skip to content

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

@wsphillips

Description

@wsphillips

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions