Race condition with local variable in @threads for loop

a has to be strictly local to @threads for. Your code seems to make it an existing local variable (see Kristoffer’s comment). Then threads interfere with each other. Make it explicitly local and it runs.

function test()
    @threads for i in 1:100
        ...
        local a = d[:a]
        ...
    end
    a = [] # ...
end

PS: edited

2 Likes