Skip to content

Commit

Permalink
support threadpools in @spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonProtter committed Jan 30, 2024
1 parent ee39369 commit d9cf481
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.7'
- '1.8'
- '1.9'
- '1.10.0'
- 'nightly'
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["Mason Protter <mason.protter@icloud.com>"]
version = "0.1.3"

[compat]
julia = "1.7"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
7 changes: 5 additions & 2 deletions src/internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ Base.schedule(t::StableTask) = (schedule(t.t); t)
Base.schedule(t, val; error=false) = (schedule(t.t, val; error); t)

"""
Similar to `Threads.@spawn` but type-stable. Creates a `Task` and schedules it to run on any available thread in the `:default` threadpool.
@spawn [:default|:interactive] expr
Similar to `Threads.@spawn` but type-stable. Creates a `Task` and schedules it to run on any available
thread in the specified threadpool (defaults to the `:default` threadpool).
"""
macro spawn(args...)
tp = QuoteNode(:default)
Expand Down Expand Up @@ -76,7 +79,7 @@ end

"""
Similar to `StableTasks.@spawn` but creates a **sticky** `Task` and schedules it to run on the thread with the given id (`thrdid`).
The task is guaranteed to stay on this thread (it won't migrate to another thread).
The task is guaranteed to stay on this thread (it won't migrate to another thread).
"""
macro spawnat(thrdid, ex)
letargs = _lift_one_interp!(ex)
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ using StableTasks: @spawn, @spawnat
t = @eval @spawn inv([1 2 ; 3 4])
@test inv([1 2 ; 3 4]) == @inferred fetch(t)

@test 2 == @inferred fetch(@spawn :interactive 1 + 1)
t = @eval @spawn :interactive inv([1 2 ; 3 4])
@test inv([1 2 ; 3 4]) == @inferred fetch(t)

s = :default
@test 2 == @inferred fetch(@spawn s 1 + 1)
t = @eval @spawn $(QuoteNode(s)) inv([1 2 ; 3 4])
@test inv([1 2 ; 3 4]) == @inferred fetch(t)

@test 2 == @inferred fetch(@spawnat 1 1 + 1)
t = @eval @spawnat 1 inv([1 2 ; 3 4])
@test inv([1 2 ; 3 4]) == @inferred fetch(t)
Expand Down

0 comments on commit d9cf481

Please sign in to comment.