Closed yuvalwas closed 1 year ago
Yeah, this isn't a problem with Trasducers.jl per se, but really just a consequence of julia's own scoping rules. I can also reproduce the problem just using Base's Threads.@threads
instead of ThreadsX.jl
Because you reference df
in the function main
as well as inside the inner function fun
, then df
becomes a captured variable in the closure and you get a race condition.
For example, if we instead write:
function main()
function fun(n)
local df = DataFrame(a = Int[], b = Int[]) # <------ Note the use of `local` here
for i in 1:2
push!(df, (i,i))
end
df
end
df = vcat(ThreadsX.map(fun, 1:2)...)
df
end
there's no problem. There's also no problem if we just used a different name outside than inside.
I'm not even sure this has to do with Transducers.jl. It took some effort to provide an MRE, as I really had no idea what was going on:
The error: