File tree Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Expand file tree Collapse file tree 2 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -59,11 +59,23 @@ function _nthreads_in_pool(tpid::Int8)
59
59
end
60
60
61
61
function _tpid_to_sym (tpid:: Int8 )
62
- return tpid == 0 ? :interactive : :default
62
+ if tpid == 0
63
+ return :interactive
64
+ elseif tpid == 1
65
+ return :default
66
+ else
67
+ throw (ArgumentError (" Unrecognized threadpool id $tpid " ))
68
+ end
63
69
end
64
70
65
71
function _sym_to_tpid (tp:: Symbol )
66
- return tp === :interactive ? Int8 (0 ) : Int8 (1 )
72
+ if tp === :interactive
73
+ return Int8 (0 )
74
+ elseif tp === :default
75
+ return Int8 (1 )
76
+ else
77
+ throw (ArgumentError (" Unrecognized threadpool name `$(repr (tp)) `" ))
78
+ end
67
79
end
68
80
69
81
"""
@@ -386,20 +398,18 @@ Hello from 4
386
398
```
387
399
"""
388
400
macro spawn (args... )
389
- tp = :default
401
+ tp = QuoteNode ( :default )
390
402
na = length (args)
391
403
if na == 2
392
404
ttype, ex = args
393
405
if ttype isa QuoteNode
394
406
ttype = ttype. value
395
- elseif ttype isa Symbol
396
- # TODO : allow unquoted symbols
397
- ttype = nothing
398
- end
399
- if ttype === :interactive || ttype === :default
400
- tp = ttype
407
+ if ttype != = :interactive && ttype != = :default
408
+ throw (ArgumentError (" unsupported threadpool in @spawn: $ttype " ))
409
+ end
410
+ tp = QuoteNode (ttype)
401
411
else
402
- throw ( ArgumentError ( " unsupported threadpool in @spawn: $ ttype" ))
412
+ tp = ttype
403
413
end
404
414
elseif na == 1
405
415
ex = args[1 ]
@@ -415,7 +425,7 @@ macro spawn(args...)
415
425
let $ (letargs... )
416
426
local task = Task ($ thunk)
417
427
task. sticky = false
418
- _spawn_set_thrpool (task, $ (QuoteNode (tp)))
428
+ _spawn_set_thrpool (task, $ (esc (tp)))
419
429
if $ (Expr (:islocal , var))
420
430
put! ($ var, task)
421
431
end
Original file line number Diff line number Diff line change @@ -9,5 +9,11 @@ using Base.Threads
9
9
@test fetch (Threads. @spawn Threads. threadpool ()) === :default
10
10
@test fetch (Threads. @spawn :default Threads. threadpool ()) === :default
11
11
@test fetch (Threads. @spawn :interactive Threads. threadpool ()) === :interactive
12
+ tp = :default
13
+ @test fetch (Threads. @spawn tp Threads. threadpool ()) === :default
14
+ tp = :interactive
15
+ @test fetch (Threads. @spawn tp Threads. threadpool ()) === :interactive
16
+ tp = :foo
17
+ @test_throws ArgumentError Threads. @spawn tp Threads. threadpool ()
12
18
@test Threads. threadpooltids (:interactive ) == [1 ]
13
19
@test Threads. threadpooltids (:default ) == [2 ]
You can’t perform that action at this time.
0 commit comments