# 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:** 2

<div class="post-metadata">

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

</div>

I don’t think you need deepcopy but you can’t just `push!` in this case because the operation is not atomic, try this instead:

> [@Thread-safe array building](https://discourse.julialang.org/t/thread-safe-array-building/3275/2):
>
> Create nthreads() number of arrays and push to them based on threadid().

---

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