Issue https://github.com/JuliaLang/julia/issues/33750 is about BitArrays not being threadsafe. My reading: changing elements of a BitArray inside a
Threads.@threads for loop can give unpredictable results.
My question is similar, but not exactly the same. In my case, the function creates a new BitArray
v inside a
Threads.@threads for loop as in
function f2(N) v = falses(N+1) x = zeros(Int,N,N) Threads.@threads for i = 1:N v = falses(N) v[i] = true x[v,i] .= i end return x end
f2(3) sometimes gives diagm(1:3), sometimes not. However, commenting out the
v = falses(N+1) statement seems to solve the problem. Alternatively, adding
local v also seems to solve the problem. Are these reliable approaches?