Skip to content

Commit b119f34

Browse files
committed
Deprecate macros mp_async and mt_async
1 parent cc050a0 commit b119f34

File tree

9 files changed

+104
-95
lines changed

9 files changed

+104
-95
lines changed

src/ParallelProcessingTools.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ include("threadlocal.jl")
1212
include("onthreads.jl")
1313
include("onprocs.jl")
1414
include("workpartition.jl")
15+
include("deprecated.jl")
1516

1617
end # module

src/deprecated.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This file is a part of ParallelProcessingTools.jl, licensed under the MIT License (MIT).
2+
3+
4+
macro onallthreads(expr)
5+
quote
6+
Base.depwarn("`@onallthreads expr` is deprecated, use `@onthreads allthreads() expr` instead.", nothing)
7+
@onthreads allthreads() $(esc(expr))
8+
end
9+
end
10+
export @onallthreads
11+
12+
13+
macro mt_async(expr)
14+
# Code taken from Base.@async and Base.Threads.@spawn:
15+
thunk = esc(:(()->($expr)))
16+
var = esc(Base.sync_varname)
17+
quote
18+
Base.depwarn("`@mt_async expr` is deprecated, use `Base.Threads.@spawn expr` instead.", nothing)
19+
local task = Task($thunk)
20+
@static if VERSION >= v"1.3.0-alpha.0"
21+
task.sticky = false
22+
end
23+
if $(Expr(:isdefined, var))
24+
push!($var, task)
25+
end
26+
schedule(task)
27+
task
28+
end
29+
end
30+
export @mt_async
31+
32+
33+
macro mp_async(expr)
34+
# Code taken from Distributed.@spawn:
35+
thunk = esc(:(()->($expr)))
36+
var = esc(Base.sync_varname)
37+
quote
38+
Base.depwarn("`@mp_async expr` is deprecated, use `Distributed.@spawn expr` instead.", nothing)
39+
local ref = Distributed.spawn_somewhere($thunk)
40+
if $(Expr(:isdefined, var))
41+
push!($var, ref)
42+
end
43+
ref
44+
end
45+
end
46+
export @mp_async
47+
48+
49+
@deprecate isdefined_local(x) isassigned(x)

src/onprocs.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,3 @@ macro onprocs(procsel, expr)
3131
end
3232
end
3333
export @onprocs
34-
35-
36-
"""
37-
@mp_async expr
38-
39-
Run `expr` asynchronously on a worker process.
40-
41-
Compatible with `@sync`.
42-
43-
Equivalent to `Distributed.@spawn expr` on Julia <= v1.2, equivalent to
44-
`Distributed.@spawn :any expr` on Julia >= v1.3.
45-
"""
46-
macro mp_async(expr)
47-
# Code taken from Distributed.@spawn:
48-
thunk = esc(:(()->($expr)))
49-
var = esc(Base.sync_varname)
50-
quote
51-
local ref = Distributed.spawn_somewhere($thunk)
52-
if $(Expr(:isdefined, var))
53-
push!($var, ref)
54-
end
55-
ref
56-
end
57-
end
58-
export @mp_async

src/onthreads.jl

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,6 @@ end
178178
export @onthreads
179179

180180

181-
macro onallthreads(expr)
182-
quote
183-
Base.depwarn("`@onallthreads expr` is deprecated, use `@onthreads allthreads() expr` instead.", nothing)
184-
$(_thread_exec_func(:(ParallelProcessingTools.allthreads()), expr))
185-
end
186-
end
187-
export @onallthreads
188-
189-
190181
function ThreadLocal{T}(f::Base.Callable) where {T}
191182
result = ThreadLocal{T}(undef)
192183
result.value
@@ -195,34 +186,6 @@ function ThreadLocal{T}(f::Base.Callable) where {T}
195186
end
196187

197188

198-
"""
199-
@mt_async expr
200-
201-
Spawn a Julia task running `expr` asynchronously.
202-
203-
Compatible with `@sync`. Uses a multi-threaded task scheduler if available (on
204-
Julia >= v1.3).
205-
206-
Equivalent to `Base.@async` on Julia <= v1.2, equivalent to
207-
`Base.Threads.@spawn` on Julia >= v1.3.
208-
"""
209-
macro mt_async(expr)
210-
# Code taken from Base.@async and Base.Threads.@spawn:
211-
thunk = esc(:(()->($expr)))
212-
var = esc(Base.sync_varname)
213-
quote
214-
local task = Task($thunk)
215-
@static if VERSION >= v"1.3.0-alpha.0"
216-
task.sticky = false
217-
end
218-
if $(Expr(:isdefined, var))
219-
push!($var, task)
220-
end
221-
schedule(task)
222-
task
223-
end
224-
end
225-
export @mt_async
226189

227190

228191
"""
@@ -257,14 +220,14 @@ macro mt_out_of_order(ex)
257220
trg = exprs[i].args[1]
258221
val = exprs[i].args[2]
259222
if val isa Expr
260-
exprs[i] = :(push!($tasks, @mt_async($(esc(val)))))
223+
exprs[i] = :(push!($tasks, Base.Threads.@spawn($(esc(val)))))
261224
push!(handle_results, :($(esc(trg)) = fetch(popfirst!($tasks))))
262225
else
263226
exprs[i] = esc(exprs[i])
264227
end
265228
elseif exprs[i] isa Expr
266229
ftvar = gensym()
267-
exprs[i] = :(push!($tasks, @mt_async($(esc(exprs[i])))))
230+
exprs[i] = :(push!($tasks, Base.Threads.@spawn($(esc(exprs[i])))))
268231
push!(handle_results, :(wait(popfirst!($tasks))))
269232
else
270233
exprs[i] = esc(exprs[i])

src/threadlocal.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ abstract type AbstractThreadLocal{T} end
2121
export AbstractThreadLocal
2222

2323

24-
@deprecate isdefined_local(x) isassigned(x)
25-
26-
2724
"""
2825
getlocalvalue(x::Any) = x
2926
getlocalvalue(x::ThreadLocal) = x[]

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Test.@testset "Package ParallelProcessingTools" begin
1111
include("test_workpartition.jl")
1212
include("test_onthreads.jl")
1313
include("test_onprocs.jl")
14+
include("test_deprecated.jl")
1415
include("test_docs.jl")
1516
end # testset
16-

test/test_deprecated.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This file is a part of ParallelProcessingTools.jl, licensed under the MIT License (MIT).
2+
3+
using Test
4+
using ParallelProcessingTools
5+
6+
using Distributed
7+
8+
9+
@testset "deprecated" begin
10+
function do_work(n)
11+
if n < 0
12+
throw(ArgumentError("n must be >= 0"))
13+
end
14+
s::Float64 = 0
15+
for i in 1:n
16+
if n % 1000 == 0
17+
yield()
18+
end
19+
s += log(abs(asin(sin(Complex(log(i), log(i))))) + 1)
20+
end
21+
s
22+
end
23+
24+
@testset "macro mt_async" begin
25+
@test_deprecated begin
26+
n = 128
27+
A = zeros(n)
28+
@sync for i in eachindex(A)
29+
@mt_async begin
30+
do_work(10^3)
31+
A[i] = log(i)
32+
end
33+
end
34+
A == log.(1:n)
35+
end
36+
end
37+
38+
@testset "macro mp_async" begin
39+
@test_deprecated begin
40+
n = 128
41+
A = Vector{Future}(undef, n)
42+
@sync for i in 1:n
43+
A[i] = @mp_async begin
44+
@assert myid() != 1
45+
log(i)
46+
end
47+
end
48+
fetch.(A) == log.(1:n)
49+
end
50+
end
51+
end

test/test_onprocs.jl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ using Distributed
3030
end) == ref_result
3131
end
3232

33-
@testset "macro mp_async" begin
34-
@test begin
35-
n = 128
36-
A = Vector{Future}(undef, n)
37-
@sync for i in 1:n
38-
A[i] = @mp_async begin
39-
@assert myid() != 1
40-
log(i)
41-
end
42-
end
43-
fetch.(A) == log.(1:n)
44-
end
45-
end
46-
4733
@testset "Examples" begin
4834
@test begin
4935
workers() == (@onprocs workers() myid())

test/test_onthreads.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ using Base.Threads
3535
end) == 1:nthreads()
3636
end
3737

38-
@testset "macro mt_async" begin
39-
@test begin
40-
n = 128
41-
A = zeros(n)
42-
@sync for i in eachindex(A)
43-
@mt_async begin
44-
do_work(10^3)
45-
A[i] = log(i)
46-
end
47-
end
48-
A == log.(1:n)
49-
end
50-
end
5138

5239
@testset "macro mt_out_of_order" begin
5340
@test begin

0 commit comments

Comments
 (0)