@@ -85,16 +85,11 @@ function _threadsfor(iter, lbody, schedule)
85
85
end
86
86
end
87
87
end
88
- if $ (schedule === :dynamic )
88
+ if $ (schedule === :dynamic || schedule === :default )
89
89
threading_run (threadsfor_fun, false )
90
- elseif ccall (:jl_in_threaded_region , Cint, ()) != 0
91
- $ (if schedule === :static
92
- :(error (" `@threads :static` cannot be used concurrently or nested" ))
93
- else
94
- # only use threads when called from outside @threads
95
- :(threadsfor_fun (onethread = true ))
96
- end )
97
- else
90
+ elseif ccall (:jl_in_threaded_region , Cint, ()) != 0 # :static
91
+ error (" `@threads :static` cannot be used concurrently or nested" )
92
+ else # :static
98
93
threading_run (threadsfor_fun, true )
99
94
end
100
95
nothing
@@ -126,21 +121,21 @@ For example, the above conditions imply that:
126
121
- Communicating between iterations using blocking primitives like `Channel`s is incorrect.
127
122
- Write only to locations not shared across iterations (unless a lock or atomic operation is used).
128
123
129
-
130
124
Schedule options are:
131
125
- `:static` creates one task per thread and divides the iterations equally among
132
126
them, assigning each task specifically to each thread.
133
127
Specifying `:static` is an error if used from inside another `@threads` loop
134
128
or from a thread other than 1.
135
- - `:dynamic` will schedule iterations dynamically to available worker threads,
129
+ - `:dynamic` (default) will schedule iterations dynamically to available worker threads,
136
130
assuming that the workload for each iteration is uniform.
137
131
138
- Without the scheduler argument, the exact scheduling is unspecified; i.e. it may be
139
- different across Julia releases. Currently, the behavior is dependent on the calling thread.
140
- The default is `:static` when called from thread 1. The loop will be executed without threading
141
- when called from other threads.
132
+ Without the scheduler argument, the exact scheduling is unspecified and varies across Julia releases.
142
133
143
- The default schedule (used when no `schedule` argument is present) is subject to change.
134
+ !!! compat "Julia 1.5"
135
+ The `schedule` argument is available as of Julia 1.5.
136
+
137
+ !!! compat "Julia 1.8"
138
+ The `:dynamic` option for the `schedule` argument is available and the default as of Julia 1.8.
144
139
145
140
For example, an illustration of the different scheduling strategies where `busywait`
146
141
is a non-yielding timed loop that runs for a number of seconds.
@@ -172,12 +167,6 @@ julia> @time begin
172
167
The `:dynamic` example takes 2 seconds since one of the non-occupied threads is able
173
168
to run two of the 1-second iterations to complete the for loop.
174
169
175
- !!! compat "Julia 1.5"
176
- The `schedule` argument is available as of Julia 1.5.
177
-
178
- !!! compat "Julia 1.8"
179
- The `:dynamic` option for the `schedule` argument is available as of Julia 1.8.
180
-
181
170
See also: [`@spawn`](@ref Threads.@spawn), [`nthreads()`](@ref Threads.nthreads),
182
171
[`threadid()`](@ref Threads.threadid), `pmap` in [`Distributed`](@ref man-distributed),
183
172
`BLAS.set_num_threads` in [`LinearAlgebra`](@ref man-linalg).
0 commit comments