Skip to content

Commit e923382

Browse files
vchuravyKristofferC
authored andcommitted
[Distributed] make nextproc use atomic operations
(cherry picked from commit fe6d61b)
1 parent e825fc5 commit e923382

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/macros.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
let nextidx = 0
3+
let nextidx = Threads.Atomic{Int}(0)
44
global nextproc
55
function nextproc()
6-
p = -1
7-
if p == -1
8-
p = workers()[(nextidx % nworkers()) + 1]
9-
nextidx += 1
10-
end
11-
p
6+
idx = Threads.atomic_add!(nextidx, 1)
7+
return workers()[(idx % nworkers()) + 1]
128
end
139
end
1410

0 commit comments

Comments
 (0)