Skip to content

Commit

Permalink
[Distributed] make nextproc use atomic operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Sep 13, 2021
1 parent 70cc57c commit 4627729
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions stdlib/Distributed/src/macros.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

let nextidx = 0
let nextidx = Threads.Atomic{Int}(0)
global nextproc
function nextproc()
p = -1
if p == -1
p = workers()[(nextidx % nworkers()) + 1]
nextidx += 1
end
p
idx = Threads.atomic_add!(nextidx, 1)
return workers()[(idx % nworkers()) + 1]
end
end

Expand Down

0 comments on commit 4627729

Please sign in to comment.