# Multithreading, preallocation of objects, threadid() and task migration

**URL:** <https://discourse.julialang.org/t/multithreading-preallocation-of-objects-threadid-and-task-migration/67640>\
**Category:** General Usage\
**Tags:** multithreading\
**Created:** [September 3, 2021, 11:58am UTC](https://discourse.julialang.org/t/multithreading-preallocation-of-objects-threadid-and-task-migration/67640 "2021-09-03T11:58:38Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [September 3, 2021, 11:44pm UTC](https://discourse.julialang.org/t/multithreading-preallocation-of-objects-threadid-and-task-migration/67640/15 "2021-09-03T23:44:46Z")

</div>

If you are going to use channels, I suggest keeping resources (e.g., pre-allocated `matrix`) as local variables as I demonstrated here: [Pattern for managing thread local storage? - #2 by tkf](https://discourse.julialang.org/t/pattern-for-managing-thread-local-storage/54023/2)

For more patterns like this, see [Concurrency patterns for controlled parallelisms](https://juliafolds.github.io/data-parallelism/tutorials/concurrency-patterns/) ([discussion](https://discourse.julialang.org/t/tutorial-concurrency-patterns-for-controlled-parallelisms/62651))

---

_[View the full topic](https://discourse.julialang.org/t/multithreading-preallocation-of-objects-threadid-and-task-migration/67640)._
