Skip to content

Commit d9cf481

Browse files
committed
support threadpools in @spawn
1 parent ee39369 commit d9cf481

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
version:
13-
- '1.7'
14-
- '1.8'
1513
- '1.9'
1614
- '1.10.0'
1715
- 'nightly'

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = ["Mason Protter <[email protected]>"]
44
version = "0.1.3"
55

66
[compat]
7-
julia = "1.7"
7+
julia = "1.9"
88

99
[extras]
1010
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/internals.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ Base.schedule(t::StableTask) = (schedule(t.t); t)
2828
Base.schedule(t, val; error=false) = (schedule(t.t, val; error); t)
2929

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

7780
"""
7881
Similar to `StableTasks.@spawn` but creates a **sticky** `Task` and schedules it to run on the thread with the given id (`thrdid`).
79-
The task is guaranteed to stay on this thread (it won't migrate to another thread).
82+
The task is guaranteed to stay on this thread (it won't migrate to another thread).
8083
"""
8184
macro spawnat(thrdid, ex)
8285
letargs = _lift_one_interp!(ex)

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ using StableTasks: @spawn, @spawnat
66
t = @eval @spawn inv([1 2 ; 3 4])
77
@test inv([1 2 ; 3 4]) == @inferred fetch(t)
88

9+
@test 2 == @inferred fetch(@spawn :interactive 1 + 1)
10+
t = @eval @spawn :interactive inv([1 2 ; 3 4])
11+
@test inv([1 2 ; 3 4]) == @inferred fetch(t)
12+
13+
s = :default
14+
@test 2 == @inferred fetch(@spawn s 1 + 1)
15+
t = @eval @spawn $(QuoteNode(s)) inv([1 2 ; 3 4])
16+
@test inv([1 2 ; 3 4]) == @inferred fetch(t)
17+
918
@test 2 == @inferred fetch(@spawnat 1 1 + 1)
1019
t = @eval @spawnat 1 inv([1 2 ; 3 4])
1120
@test inv([1 2 ; 3 4]) == @inferred fetch(t)

0 commit comments

Comments
 (0)