@@ -85,16 +85,11 @@ function _threadsfor(iter, lbody, schedule)
8585 end
8686 end
8787 end
88- if $ (schedule === :dynamic )
88+ if $ (schedule === :dynamic || schedule === :default )
8989 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
9893 threading_run (threadsfor_fun, true )
9994 end
10095 nothing
@@ -126,21 +121,21 @@ For example, the above conditions imply that:
126121- Communicating between iterations using blocking primitives like `Channel`s is incorrect.
127122- Write only to locations not shared across iterations (unless a lock or atomic operation is used).
128123
129-
130124Schedule options are:
131125- `:static` creates one task per thread and divides the iterations equally among
132126 them, assigning each task specifically to each thread.
133127 Specifying `:static` is an error if used from inside another `@threads` loop
134128 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,
136130 assuming that the workload for each iteration is uniform.
137131
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.
142133
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.
144139
145140For example, an illustration of the different scheduling strategies where `busywait`
146141is a non-yielding timed loop that runs for a number of seconds.
@@ -172,12 +167,6 @@ julia> @time begin
172167The `:dynamic` example takes 2 seconds since one of the non-occupied threads is able
173168to run two of the 1-second iterations to complete the for loop.
174169
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-
181170See also: [`@spawn`](@ref Threads.@spawn), [`nthreads()`](@ref Threads.nthreads),
182171[`threadid()`](@ref Threads.threadid), `pmap` in [`Distributed`](@ref man-distributed),
183172`BLAS.set_num_threads` in [`LinearAlgebra`](@ref man-linalg).
0 commit comments