~ninjin/julia-nix

5fb27b2cd4963bc11621daa15237e2bb2c266d8e — Valentin Churavy 2 years ago 5b243c8 + 4627729
Merge pull request #42238 from JuliaLang/vc/distributed_rr

[Distributed] make nextproc use atomic operations
1 files changed, 3 insertions(+), 7 deletions(-)

M stdlib/Distributed/src/macros.jl
M stdlib/Distributed/src/macros.jl => stdlib/Distributed/src/macros.jl +3 -7
@@ 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