# Safe loop with push! multi-threading

**URL:** <https://discourse.julialang.org/t/safe-loop-with-push-multi-threading/41892>\
**Category:** Performance\
**Tags:** performance, parallel\
**Created:** [June 22, 2020, 8:56pm UTC](https://discourse.julialang.org/t/safe-loop-with-push-multi-threading/41892 "2020-06-22T20:56:33Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Post date:** [June 22, 2020, 9:31pm UTC](https://discourse.julialang.org/t/safe-loop-with-push-multi-threading/41892/4 "2020-06-22T21:31:28Z")

</div>

I am trying to adapt the code of [Thread-safe array building - #2 by yuyichao](https://discourse.julialang.org/t/thread-safe-array-building/3275/2) for `Array{Float64,1}`:

```julia
num_monte = Int(1e6)
solution_data = Vector{Array{Float64,1}}()
for i in 1:Threads.nthreads()
  push!(solution_data, Array{Float64,1}[])
end
Threads.@threads for i in 1:num_monte
  push!(solution_data[Threads.threadid()],[1.0; 2.0])
end

```

TaskFailedException:  
MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type Float64  
Closest candidates are:  
convert(::Type{T}, !Matched::Ratios.SimpleRatio{S}) where {T\<:AbstractFloat, S} at /home/mat/.julia/packages/Ratios/uRs4y/src/Ratios.jl:14  
convert(::Type{T}, !Matched::T) where T\<:Number at number.jl:6  
convert(::Type{T}, !Matched::Number) where T\<:Number at number.jl:7  
…  
Stacktrace:  
[1] push!(::Array{Float64,1}, ::Array{Float64,1}) at ./array.jl:912  
[2] macro expansion at ./In[87]:7 [inlined]  
[3] (::var"#804#threadsfor\_fun#28"{UnitRange{Int64}})(::Bool) at ./threadingconstructs.jl:61  
[4] (::var"#804#threadsfor\_fun#28"{UnitRange{Int64}})() at ./threadingconstructs.jl:28

Stacktrace:  
[1] wait(::Task) at ./task.jl:267  
[2] macro expansion at ./threadingconstructs.jl:69 [inlined]  
[3] macro expansion at ./util.jl:175 [inlined]  
[4] top-level scope at ./In[87]:6

---

_[View the full topic](https://discourse.julialang.org/t/safe-loop-with-push-multi-threading/41892)._
