# \#task\_local\_storage

**URL:** https://discourse.julialang.org/tag/task-local-storage/1861.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Reusing @local cache when multithreading](https://discourse.julialang.org/t/reusing-local-cache-when-multithreading/136579)

<div class="topic-metadata">

**Author:** [@amousavi](https://discourse.julialang.org/u/amousavi)\
**Replies:** 1\
**Last updated:** [April 6, 2026, 1:30am UTC](https://discourse.julialang.org/t/reusing-local-cache-when-multithreading/136579 "2026-04-06T01:30:17Z")

</div>

Hi everyone! I am trying to update an old project of mine where I have three nested for loops as such: scratch = zeros(Float32, tree\_nodes, nthreads()) collect\_here = zeros(Float32, nthreads()) for i in eachindex(V) @…

---

## [Avoiding false sharing in parallel loop without collecting](https://discourse.julialang.org/t/avoiding-false-sharing-in-parallel-loop-without-collecting/134798)

<div class="topic-metadata">

**Author:** [@oscarvdvelde](https://discourse.julialang.org/u/oscarvdvelde)\
**Replies:** 8\
**Last updated:** [December 30, 2025, 8:59pm UTC](https://discourse.julialang.org/t/avoiding-false-sharing-in-parallel-loop-without-collecting/134798 "2025-12-30T20:59:29Z")

</div>

I have this function with a parallel loop that probably can benefit from elimination of false sharing. function(t,x,y,z) per\_point\_result\_array = ... #preinitialized @tasks for c in eachindex(gridcells) …

---

## [How many task can you create (related to wold age)?](https://discourse.julialang.org/t/how-many-task-can-you-create-related-to-wold-age/132807)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 1\
**Last updated:** [October 1, 2025, 4:57pm UTC](https://discourse.julialang.org/t/how-many-task-can-you-create-related-to-wold-age/132807 "2025-10-01T16:57:41Z")

</div>

\[Possible should be in internals category?\] I see the world age is increased when I create tasks so I ask, and world age is an UInt i.e. 32-bit on 32-bit platforms. Certain language features capture the current task’s…

---

## [Task local storage and scoped values: What they are used for](https://discourse.julialang.org/t/task-local-storage-and-scoped-values-what-they-are-used-for/132045)

<div class="topic-metadata">

**Author:** [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Replies:** 12\
**Last updated:** [September 22, 2025, 7:46am UTC](https://discourse.julialang.org/t/task-local-storage-and-scoped-values-what-they-are-used-for/132045 "2025-09-22T07:46:55Z")

</div>

A recent Slack thread discussed what the purpose of task local storage (TLS) and scoped values was. Since these features of Julia are a little obscure, @Krastanov suggested I post them to Discourse for posterity. @vchur…

---

## [\`task\_local\_storage\`, why and where?](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670)

<div class="topic-metadata">

**Author:** [@Pedro](https://discourse.julialang.org/u/Pedro)\
**Replies:** 3\
**Last updated:** [February 8, 2025, 9:58am UTC](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670 "2025-02-08T09:58:51Z")

</div>

I recently discovered that there exists such function as task\_local\_storage for task. It’s exported. Can anyone give me an example of practical application of such functionality?

---

## [Is it possible to read another Task's task\_local\_storage](https://discourse.julialang.org/t/is-it-possible-to-read-another-tasks-task-local-storage/110324)

<div class="topic-metadata">

**Author:** [@rdavis120](https://discourse.julialang.org/u/rdavis120)\
**Replies:** 1\
**Last updated:** [February 17, 2024, 2:29am UTC](https://discourse.julialang.org/t/is-it-possible-to-read-another-tasks-task-local-storage/110324 "2024-02-17T02:29:03Z")

</div>

Is it possible to read the task\_local\_storage of a Task? For example, if you were to spawn several long running child tasks and you keep the handles to the child Tasks, can another task read the storage using those hand…

---

## [How to use many (non-sticky) tasks while maximizing local storage reuse?](https://discourse.julialang.org/t/how-to-use-many-non-sticky-tasks-while-maximizing-local-storage-reuse/100279)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 9\
**Last updated:** [August 1, 2023, 12:53pm UTC](https://discourse.julialang.org/t/how-to-use-many-non-sticky-tasks-while-maximizing-local-storage-reuse/100279 "2023-08-01T12:53:08Z")

</div>

After reading the WIP blogpost https://github.com/JuliaLang/www.julialang.org/pull/1904, I’m trying to adapt to the new recommended approach to multithreading, now that tasks can migrate between threads. I would like to …

---

## [How to clear out buffers stored in \`task\_local\_storage\`](https://discourse.julialang.org/t/how-to-clear-out-buffers-stored-in-task-local-storage/100079)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 2\
**Last updated:** [June 9, 2023, 12:15pm UTC](https://discourse.julialang.org/t/how-to-clear-out-buffers-stored-in-task-local-storage/100079 "2023-06-09T12:15:58Z")

</div>

Before, the buffer is inside my struct and those are reclaimed whenever objects are GC-ed. If I used task\_local\_storage, the buffer would accumulate infinitely on the main task, should I use finalize() to clear out the t…

---

## [Add a value to task local storage if it is not already present](https://discourse.julialang.org/t/add-a-value-to-task-local-storage-if-it-is-not-already-present/89909)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 2\
**Last updated:** [November 8, 2022, 7:43am UTC](https://discourse.julialang.org/t/add-a-value-to-task-local-storage-if-it-is-not-already-present/89909 "2022-11-08T07:43:54Z")

</div>

I have a workload that I want to multi thread. This involves calling a function in parallel, that needs some work space for computing. The following rules apply: There may never be two computations using the same works…
