Multithreading unstable with JuMP

I hit this same issue recently, see the link. julia scope rule is not very intuitively in this case. An assignment to a variable, before or after, the @threads for loop will make it have an scope outside the threads section.

Run this example julia t3 test.jl

# test.jl
import Base.Threads: @threads, nthreads

function test()
    @threads :static for i in 1:100

        d = Dict(:a => Dict())
        a = d[:a]
        @assert a === d[:a]

        # Line 12: This throw an AssertionError
        for j in 1:100; @assert a === d[:a] end 
    end
    a = [] # If this line is commented the problem disappears 
end

println("Running test (-t$(nthreads()))")
for i = 1:500; test() end