Skip to content

Commit af4b813

Browse files
committed
Remove code specific to older Julia versions
1 parent b119f34 commit af4b813

File tree

4 files changed

+6
-135
lines changed

4 files changed

+6
-135
lines changed

src/onthreads.jl

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ function _current_thread_selected(threadsel::Union{Integer,AbstractVector{<:Inte
77
end
88

99

10-
@static if VERSION >= v"1.3.0-alpha.0"
11-
12-
1310
# From Julia PR 32477:
1411
function _run_on(t::Task, tid)
1512
@assert !istaskstarted(t)
@@ -52,82 +49,12 @@ function _thread_exec_func(threadsel, expr)
5249
end
5350

5451

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-
12552
"""
12653
allthreads()
12754
128-
Convencience function, returns `1:Base.Threads.nthreads()`.
55+
Convencience function, returns an equivalent of `1:Base.Threads.nthreads()`.
12956
"""
130-
allthreads() = 1:nthreads()
57+
allthreads() = Base.OneTo(Base.Threads.nthreads())
13158
export allthreads
13259

13360

@@ -140,14 +67,6 @@ Execute code in `expr` in parallel on the threads in `threadsel`.
14067
If `threadsel == Base.Threads.threadid()`, `expr` is run on the current
14168
tread with only minimal overhead.
14269
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-
15170
Example 1:
15271
15372
```juliaexpr
@@ -191,8 +110,8 @@ end
191110
"""
192111
@mt_out_of_order begin expr... end
193112
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.
196115
197116
Example:
198117

src/threadlocal.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,5 @@ Base.get!(x::ThreadLocal, default) = get!(() -> default, x)
124124
Base.isassigned(x::ThreadLocal) = isassigned(x.value, threadid())
125125

126126
function getallvalues(x::ThreadLocal)
127-
@static if VERSION >= v"1.3.0-alpha.0"
128-
x.value
129-
else
130-
if !Base.Threads.in_threaded_loop[]
131-
x.value
132-
else
133-
throw(InvalidStateException("Can not access thread local values across threads in multi-threaded code sections"))
134-
end
135-
end
127+
x.value
136128
end

src/threadsafe.jl

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,7 @@ abstract type ThreadSafe{T} end
66

77

88
export ThreadSafeReentrantLock
9-
10-
@static if VERSION >= v"1.2-DEV.28"
11-
const ThreadSafeReentrantLock = ReentrantLock
12-
else
13-
struct ThreadSafeReentrantLock
14-
thread_lock::RecursiveSpinLock
15-
task_lock::ReentrantLock
16-
17-
ThreadSafeReentrantLock() = new(RecursiveSpinLock(), ReentrantLock())
18-
end
19-
20-
function Base.lock(l::ThreadSafeReentrantLock)
21-
# @debug "LOCKING $l"
22-
lock(l.thread_lock)
23-
try
24-
lock(l.task_lock)
25-
catch err
26-
unlock(l.thread_lock)
27-
rethrow()
28-
end
29-
end
30-
31-
32-
function Base.unlock(l::ThreadSafeReentrantLock)
33-
# @debug "UNLOCKING $l"
34-
try
35-
unlock(l.task_lock)
36-
finally
37-
unlock(l.thread_lock)
38-
end
39-
end
40-
end
41-
9+
const ThreadSafeReentrantLock = ReentrantLock
4210

4311

4412
export LockableValue

test/test_threadsafe.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ using Base.Threads
99

1010
@testset "ThreadSafeReentrantLock" begin
1111
tsReLock = @inferred ThreadSafeReentrantLock()
12-
@static if VERSION < v"1.2-DEV.28"
13-
lock(tsReLock)
14-
@test islocked(tsReLock.thread_lock)
15-
@test islocked(tsReLock.task_lock)
16-
unlock(tsReLock)
17-
@test !islocked(tsReLock.thread_lock)
18-
@test !islocked(tsReLock.task_lock)
19-
end
2012
end
2113

2214
@testset "LockableValue" begin

0 commit comments

Comments
 (0)