@@ -31,10 +31,11 @@ Timer(t -> killjob("KILLING BY THREAD TEST WATCHDOG\n"), 1200)
31
31
@testset """ threads_exec.jl with JULIA_NUM_THREADS == $(ENV [" JULIA_NUM_THREADS" ]) """ begin
32
32
33
33
@test Threads. threadid () == 1
34
- @test 1 <= threadpoolsize () <= Threads. maxthreadid ()
34
+ @test threadpool () in (:interactive , :default ) # thread 1 could be in the interactive pool
35
+ @test 1 <= threadpoolsize (:default ) <= Threads. maxthreadid ()
35
36
36
37
# basic lock check
37
- if threadpoolsize () > 1
38
+ if threadpoolsize (:default ) > 1
38
39
let lk = SpinLock ()
39
40
c1 = Base. Event ()
40
41
c2 = Base. Event ()
56
57
57
58
# threading constructs
58
59
59
- let a = zeros (Int, 2 * threadpoolsize ())
60
+ @testset " @threads and @spawn threadpools" begin
61
+ @threads for i in 1 : 1
62
+ @test threadpool () == :default
63
+ end
64
+ @test fetch (Threads. @spawn threadpool ()) == :default
65
+ @test fetch (Threads. @spawn :default threadpool ()) == :default
66
+ if threadpoolsize (:interactive ) > 0
67
+ @test fetch (Threads. @spawn :interactive threadpool ()) == :interactive
68
+ end
69
+ end
70
+
71
+ let a = zeros (Int, 2 * threadpoolsize (:default ))
60
72
@threads for i = 1 : length (a)
61
73
@sync begin
62
74
@async begin
76
88
77
89
# parallel loop with parallel atomic addition
78
90
function threaded_loop (a, r, x)
79
- counter = Threads. Atomic {Int} (min (threadpoolsize (), length (r)))
91
+ counter = Threads. Atomic {Int} (min (threadpoolsize (:default ), length (r)))
80
92
@threads for i in r
81
93
# synchronize the start given that each partition is started sequentially,
82
94
# meaning that without the wait, if the loop is too fast the iteration can happen in order
429
441
for T in intersect ((Int32, Int64, Float32, Float64), Base. Threads. atomictypes)
430
442
var = Atomic {T} ()
431
443
nloops = 1000
432
- di = threadpoolsize ()
444
+ di = threadpoolsize (:default )
433
445
@threads for i in 1 : di
434
446
test_atomic_cas! (var, i: di: nloops)
435
447
end
@@ -519,13 +531,13 @@ function test_thread_cfunction()
519
531
@test cfs[1 ] == cf1
520
532
@test cfs[2 ] == cf (fs[2 ])
521
533
@test length (unique (cfs)) == 1000
522
- ok = zeros (Int, threadpoolsize ())
534
+ ok = zeros (Int, threadpoolsize (:default ))
523
535
@threads :static for i in 1 : 10000
524
536
i = mod1 (i, 1000 )
525
537
fi = fs[i]
526
538
cfi = cf (fi)
527
539
GC. @preserve cfi begin
528
- ok[threadid ()] += (cfi === cfs[i])
540
+ ok[threadid () - threadpoolsize ( :interactive ) ] += (cfi === cfs[i])
529
541
end
530
542
end
531
543
@test sum (ok) == 10000
@@ -582,17 +594,17 @@ test_nested_loops()
582
594
583
595
function test_thread_too_few_iters ()
584
596
x = Atomic ()
585
- a = zeros (Int, threadpoolsize ()+ 2 )
586
- threaded_loop (a, 1 : threadpoolsize ()- 1 , x)
587
- found = zeros (Bool, threadpoolsize ()+ 2 )
588
- for i= 1 : threadpoolsize ()- 1
597
+ a = zeros (Int, threadpoolsize (:default )+ 2 )
598
+ threaded_loop (a, 1 : threadpoolsize (:default )- 1 , x)
599
+ found = zeros (Bool, threadpoolsize (:default )+ 2 )
600
+ for i= 1 : threadpoolsize (:default )- 1
589
601
found[a[i]] = true
590
602
end
591
- @test x[] == threadpoolsize ()- 1
603
+ @test x[] == threadpoolsize (:default )- 1
592
604
# Next test checks that all loop iterations ran,
593
605
# and were unique (via pigeon-hole principle).
594
- @test ! (false in found[1 : threadpoolsize ()- 1 ])
595
- @test ! (true in found[threadpoolsize (): end ])
606
+ @test ! (false in found[1 : threadpoolsize (:default )- 1 ])
607
+ @test ! (true in found[threadpoolsize (:default ): end ])
596
608
end
597
609
test_thread_too_few_iters ()
598
610
@@ -734,10 +746,10 @@ function _atthreads_with_error(a, err)
734
746
end
735
747
a
736
748
end
737
- @test_throws CompositeException _atthreads_with_error (zeros (threadpoolsize ()), true )
738
- let a = zeros (threadpoolsize ())
749
+ @test_throws CompositeException _atthreads_with_error (zeros (threadpoolsize (:default )), true )
750
+ let a = zeros (threadpoolsize (:default ))
739
751
_atthreads_with_error (a, false )
740
- @test a == [1 : threadpoolsize ();]
752
+ @test a == [threadpoolsize ( :interactive ) .+ ( 1 : threadpoolsize (:default ) );]
741
753
end
742
754
743
755
# static schedule
@@ -748,11 +760,11 @@ function _atthreads_static_schedule(n)
748
760
end
749
761
return ids
750
762
end
751
- @test _atthreads_static_schedule (threadpoolsize ()) == 1 : threadpoolsize ()
752
- @test _atthreads_static_schedule (1 ) == [1 ;]
763
+ @test _atthreads_static_schedule (threadpoolsize (:default )) == threadpoolsize ( :interactive ) .+ ( 1 : threadpoolsize (:default ) )
764
+ @test _atthreads_static_schedule (1 ) == [threadpoolsize ( :interactive ) + 1 ;]
753
765
@test_throws (
754
766
" `@threads :static` cannot be used concurrently or nested" ,
755
- @threads (for i = 1 : 1 ; _atthreads_static_schedule (threadpoolsize ()); end ),
767
+ @threads (for i = 1 : 1 ; _atthreads_static_schedule (threadpoolsize (:default )); end ),
756
768
)
757
769
758
770
# dynamic schedule
@@ -765,35 +777,35 @@ function _atthreads_dynamic_schedule(n)
765
777
end
766
778
return inc[], flags
767
779
end
768
- @test _atthreads_dynamic_schedule (threadpoolsize ()) == (threadpoolsize (), ones (threadpoolsize ()))
780
+ @test _atthreads_dynamic_schedule (threadpoolsize (:default )) == (threadpoolsize (:default ), ones (threadpoolsize (:default )))
769
781
@test _atthreads_dynamic_schedule (1 ) == (1 , ones (1 ))
770
782
@test _atthreads_dynamic_schedule (10 ) == (10 , ones (10 ))
771
- @test _atthreads_dynamic_schedule (threadpoolsize () * 2 ) == (threadpoolsize () * 2 , ones (threadpoolsize () * 2 ))
783
+ @test _atthreads_dynamic_schedule (threadpoolsize (:default ) * 2 ) == (threadpoolsize (:default ) * 2 , ones (threadpoolsize (:default ) * 2 ))
772
784
773
785
# nested dynamic schedule
774
786
function _atthreads_dynamic_dynamic_schedule ()
775
787
inc = Threads. Atomic {Int} (0 )
776
- Threads. @threads :dynamic for _ = 1 : threadpoolsize ()
777
- Threads. @threads :dynamic for _ = 1 : threadpoolsize ()
788
+ Threads. @threads :dynamic for _ = 1 : threadpoolsize (:default )
789
+ Threads. @threads :dynamic for _ = 1 : threadpoolsize (:default )
778
790
Threads. atomic_add! (inc, 1 )
779
791
end
780
792
end
781
793
return inc[]
782
794
end
783
- @test _atthreads_dynamic_dynamic_schedule () == threadpoolsize () * threadpoolsize ()
795
+ @test _atthreads_dynamic_dynamic_schedule () == threadpoolsize (:default ) * threadpoolsize (:default )
784
796
785
797
function _atthreads_static_dynamic_schedule ()
786
- ids = zeros (Int, threadpoolsize ())
798
+ ids = zeros (Int, threadpoolsize (:default ))
787
799
inc = Threads. Atomic {Int} (0 )
788
- Threads. @threads :static for i = 1 : threadpoolsize ()
800
+ Threads. @threads :static for i = 1 : threadpoolsize (:default )
789
801
ids[i] = Threads. threadid ()
790
- Threads. @threads :dynamic for _ = 1 : threadpoolsize ()
802
+ Threads. @threads :dynamic for _ = 1 : threadpoolsize (:default )
791
803
Threads. atomic_add! (inc, 1 )
792
804
end
793
805
end
794
806
return ids, inc[]
795
807
end
796
- @test _atthreads_static_dynamic_schedule () == (1 : threadpoolsize () , threadpoolsize () * threadpoolsize ())
808
+ @test _atthreads_static_dynamic_schedule () == (threadpoolsize ( :interactive ) .+ ( 1 : threadpoolsize (:default )) , threadpoolsize (:default ) * threadpoolsize (:default ))
797
809
798
810
# errors inside @threads :dynamic
799
811
function _atthreads_dynamic_with_error (a)
@@ -802,7 +814,7 @@ function _atthreads_dynamic_with_error(a)
802
814
end
803
815
a
804
816
end
805
- @test_throws " user error in the loop body" _atthreads_dynamic_with_error (zeros (threadpoolsize ()))
817
+ @test_throws " user error in the loop body" _atthreads_dynamic_with_error (zeros (threadpoolsize (:default )))
806
818
807
819
# ###
808
820
# :greedy
@@ -817,57 +829,57 @@ function _atthreads_greedy_schedule(n)
817
829
end
818
830
return inc[], flags
819
831
end
820
- @test _atthreads_greedy_schedule (threadpoolsize ()) == (threadpoolsize (), ones (threadpoolsize ()))
832
+ @test _atthreads_greedy_schedule (threadpoolsize (:default )) == (threadpoolsize (:default ), ones (threadpoolsize (:default )))
821
833
@test _atthreads_greedy_schedule (1 ) == (1 , ones (1 ))
822
834
@test _atthreads_greedy_schedule (10 ) == (10 , ones (10 ))
823
- @test _atthreads_greedy_schedule (threadpoolsize () * 2 ) == (threadpoolsize () * 2 , ones (threadpoolsize () * 2 ))
835
+ @test _atthreads_greedy_schedule (threadpoolsize (:default ) * 2 ) == (threadpoolsize (:default ) * 2 , ones (threadpoolsize (:default ) * 2 ))
824
836
825
837
# nested greedy schedule
826
838
function _atthreads_greedy_greedy_schedule ()
827
839
inc = Threads. Atomic {Int} (0 )
828
- Threads. @threads :greedy for _ = 1 : threadpoolsize ()
829
- Threads. @threads :greedy for _ = 1 : threadpoolsize ()
840
+ Threads. @threads :greedy for _ = 1 : threadpoolsize (:default )
841
+ Threads. @threads :greedy for _ = 1 : threadpoolsize (:default )
830
842
Threads. atomic_add! (inc, 1 )
831
843
end
832
844
end
833
845
return inc[]
834
846
end
835
- @test _atthreads_greedy_greedy_schedule () == threadpoolsize () * threadpoolsize ()
847
+ @test _atthreads_greedy_greedy_schedule () == threadpoolsize (:default ) * threadpoolsize (:default )
836
848
837
849
function _atthreads_greedy_dynamic_schedule ()
838
850
inc = Threads. Atomic {Int} (0 )
839
- Threads. @threads :greedy for _ = 1 : threadpoolsize ()
840
- Threads. @threads :dynamic for _ = 1 : threadpoolsize ()
851
+ Threads. @threads :greedy for _ = 1 : threadpoolsize (:default )
852
+ Threads. @threads :dynamic for _ = 1 : threadpoolsize (:default )
841
853
Threads. atomic_add! (inc, 1 )
842
854
end
843
855
end
844
856
return inc[]
845
857
end
846
- @test _atthreads_greedy_dynamic_schedule () == threadpoolsize () * threadpoolsize ()
858
+ @test _atthreads_greedy_dynamic_schedule () == threadpoolsize (:default ) * threadpoolsize (:default )
847
859
848
860
function _atthreads_dymamic_greedy_schedule ()
849
861
inc = Threads. Atomic {Int} (0 )
850
- Threads. @threads :dynamic for _ = 1 : threadpoolsize ()
851
- Threads. @threads :greedy for _ = 1 : threadpoolsize ()
862
+ Threads. @threads :dynamic for _ = 1 : threadpoolsize (:default )
863
+ Threads. @threads :greedy for _ = 1 : threadpoolsize (:default )
852
864
Threads. atomic_add! (inc, 1 )
853
865
end
854
866
end
855
867
return inc[]
856
868
end
857
- @test _atthreads_dymamic_greedy_schedule () == threadpoolsize () * threadpoolsize ()
869
+ @test _atthreads_dymamic_greedy_schedule () == threadpoolsize (:default ) * threadpoolsize (:default )
858
870
859
871
function _atthreads_static_greedy_schedule ()
860
- ids = zeros (Int, threadpoolsize ())
872
+ ids = zeros (Int, threadpoolsize (:default ))
861
873
inc = Threads. Atomic {Int} (0 )
862
- Threads. @threads :static for i = 1 : threadpoolsize ()
874
+ Threads. @threads :static for i = 1 : threadpoolsize (:default )
863
875
ids[i] = Threads. threadid ()
864
- Threads. @threads :greedy for _ = 1 : threadpoolsize ()
876
+ Threads. @threads :greedy for _ = 1 : threadpoolsize (:default )
865
877
Threads. atomic_add! (inc, 1 )
866
878
end
867
879
end
868
880
return ids, inc[]
869
881
end
870
- @test _atthreads_static_greedy_schedule () == (1 : threadpoolsize () , threadpoolsize () * threadpoolsize ())
882
+ @test _atthreads_static_greedy_schedule () == (threadpoolsize ( :interactive ) .+ ( 1 : threadpoolsize (:default )) , threadpoolsize (:default ) * threadpoolsize (:default ))
871
883
872
884
# errors inside @threads :greedy
873
885
function _atthreads_greedy_with_error (a)
@@ -876,7 +888,7 @@ function _atthreads_greedy_with_error(a)
876
888
end
877
889
a
878
890
end
879
- @test_throws " user error in the loop body" _atthreads_greedy_with_error (zeros (threadpoolsize ()))
891
+ @test_throws " user error in the loop body" _atthreads_greedy_with_error (zeros (threadpoolsize (:default )))
880
892
881
893
# ###
882
894
# multi-argument loop
@@ -1109,7 +1121,7 @@ function check_sync_end_race()
1109
1121
nnotscheduled += y === :notscheduled
1110
1122
end
1111
1123
# Useful for tuning the test:
1112
- @debug " `check_sync_end_race` done" threadpoolsize () ncompleted nnotscheduled nerror
1124
+ @debug " `check_sync_end_race` done" threadpoolsize (:default ) ncompleted nnotscheduled nerror
1113
1125
finally
1114
1126
done[] = true
1115
1127
end
@@ -1123,7 +1135,7 @@ end
1123
1135
1124
1136
# issue #41546, thread-safe package loading
1125
1137
@testset " package loading" begin
1126
- ntasks = max (threadpoolsize (), 4 )
1138
+ ntasks = max (threadpoolsize (:default ), 4 )
1127
1139
ch = Channel {Bool} (ntasks)
1128
1140
barrier = Base. Event ()
1129
1141
old_act_proj = Base. ACTIVE_PROJECT[]
0 commit comments