~ninjin/julia-nix

4627729651a08cd15b556995f0672007884cf873 — Valentin Churavy 2 years ago 70cc57c
[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