Skip to content

Commit

Permalink
init_multi: Be more thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsamaroo committed Oct 29, 2023
1 parent 7057e47 commit 6975ce9
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1318,18 +1318,16 @@ end

using Random: randstring

let inited = false
# do initialization that's only needed when there is more than 1 processor
global function init_multi()
if !inited
inited = true
push!(Base.package_callbacks, _require_callback)
atexit(terminate_all_workers)
init_bind_addr()
cluster_cookie(randstring(HDR_COOKIE_LEN))
end
return nothing
# do initialization that's only needed when there is more than 1 processor
const inited = Threads.Atomic{Bool}(false)
function init_multi()
if !Threads.atomic_cas!(inited, false, true)
push!(Base.package_callbacks, _require_callback)
atexit(terminate_all_workers)
init_bind_addr()
cluster_cookie(randstring(HDR_COOKIE_LEN))
end
return nothing
end

function init_parallel()
Expand Down

0 comments on commit 6975ce9

Please sign in to comment.