@@ -7,9 +7,6 @@ function _current_thread_selected(threadsel::Union{Integer,AbstractVector{<:Inte
7
7
end
8
8
9
9
10
- @static if VERSION >= v " 1.3.0-alpha.0"
11
-
12
-
13
10
# From Julia PR 32477:
14
11
function _run_on (t:: Task , tid)
15
12
@assert ! istaskstarted (t)
@@ -52,82 +49,12 @@ function _thread_exec_func(threadsel, expr)
52
49
end
53
50
54
51
55
- else # VERSION < v"1.3.0-alpha.0"
56
-
57
-
58
- const _thread_local_error_err = ThreadLocal {Any} (undef)
59
- const _thread_local_error_set = ThreadLocal {Bool} (undef)
60
-
61
-
62
- _clear_thread_local_errors () = fill! (getallvalues (_thread_local_error_set), false )
63
-
64
- function _check_thread_local_errors ()
65
- i = something (findfirst (isequal (true ), getallvalues (_thread_local_error_set)), 0 )
66
- (i > 0 ) && throw (getallvalues (_thread_local_error_err)[i])
67
- nothing
68
- end
69
-
70
- function _set_thread_local_error (err)
71
- _thread_local_error_err[] = err
72
- _thread_local_error_set[] = true
73
- end
74
-
75
- function _check_threadsel (threadsel:: Union{Integer,AbstractVector{<:Integer}} )
76
- if ! checkindex (Bool, allthreads (), threadsel)
77
- throw (ArgumentError (" Thread selection not within available threads" ))
78
- end
79
- threadsel
80
- end
81
-
82
-
83
- function _run_on_threads (f)
84
- try
85
- @assert (! Base. Threads. in_threaded_loop[], " Can't nest threaded execution" )
86
- _clear_thread_local_errors ()
87
- Base. Threads. in_threaded_loop[] = true
88
- ccall (:jl_threading_run , Ref{Cvoid}, (Any,), f)
89
- finally
90
- Base. Threads. in_threaded_loop[] = false
91
- _check_thread_local_errors ()
92
- end
93
- end
94
-
95
-
96
- function _thread_exec_func (threadsel, expr)
97
- quote
98
- local thread_body_wrapper_fun
99
- let threadsel_eval = $ (esc (threadsel))
100
- function thread_body_wrapper_fun ()
101
- try
102
- if Base. Threads. threadid () in threadsel_eval
103
- $ (esc (expr))
104
- end
105
- catch err
106
- _set_thread_local_error (err)
107
- rethrow ()
108
- end
109
- end
110
- if _current_thread_selected (threadsel_eval)
111
- thread_body_wrapper_fun ()
112
- else
113
- _run_on_threads (thread_body_wrapper_fun)
114
- end
115
- nothing
116
- end
117
- end
118
- end
119
-
120
-
121
- end # Julia version-dependent code
122
-
123
-
124
-
125
52
"""
126
53
allthreads()
127
54
128
- Convencience function, returns `1:Base.Threads.nthreads()`.
55
+ Convencience function, returns an equivalent of `1:Base.Threads.nthreads()`.
129
56
"""
130
- allthreads () = 1 : nthreads ()
57
+ allthreads () = Base . OneTo (Base . Threads . nthreads () )
131
58
export allthreads
132
59
133
60
@@ -140,14 +67,6 @@ Execute code in `expr` in parallel on the threads in `threadsel`.
140
67
If `threadsel == Base.Threads.threadid()`, `expr` is run on the current
141
68
tread with only minimal overhead.
142
69
143
- Note: Currently, multiple `@onthreads` sections will not run in parallel
144
- to each other, even if they use disjunct sets of threads, due to limitations
145
- of the Julia multithreading implementation. This restriction is likely to
146
- disappear in future Julia versions.
147
-
148
- In contrast to `Base.Threads.@threads`, `@onthreads` does forward
149
- exceptions to the caller.
150
-
151
70
Example 1:
152
71
153
72
```juliaexpr
191
110
"""
192
111
@mt_out_of_order begin expr... end
193
112
194
- Runs all top-level expressions in `begin expr... end` on parallel tasks.
195
- On Julia >= v1.3, the tasks will run multi-threaded.
113
+ Runs all top-level expressions in `begin expr... end` on parallel
114
+ multi-threaded tasks .
196
115
197
116
Example:
198
117
0 commit comments