# \`task\_local\_storage\`, why and where?

**URL:** https://discourse.julialang.org/t/task-local-storage-why-and-where/125670
**Category:** General Usage
**Tags:** multithreading, task\_local\_storage
**Created:** [February 7, 2025, 8:39pm UTC](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670 "2025-02-07T20:39:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.julialang.org/u/Pedro)
#### Post date: [February 7, 2025, 8:39pm UTC](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670/1 "2025-02-07T20:39:04Z")

</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?

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [February 7, 2025, 10:31pm UTC](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670/2 "2025-02-07T22:31:03Z")

</div>

> **[Thread-Safe Storage · OhMyThreads.jl](https://juliafolds2.github.io/OhMyThreads.jl/stable/literate/tls/tls/#TLS)**
>
> Documentation for OhMyThreads.jl.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 8, 2025, 1:01am UTC](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670/3 "2025-02-08T01:01:40Z")

</div>

> [@Pedro](#):
>
> Can anyone give me an example of practical application of such functionality?

For example, I just used it in DecFP.jl to make the rounding mode thread-safe: [Thread safety: per-task state rather than per-thread by stevengj · Pull Request #185 · JuliaMath/DecFP.jl · GitHub](https://github.com/JuliaMath/DecFP.jl/pull/185)

---

<div class="post-metadata">

### Author: ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.julialang.org/u/Pedro)
#### Post date: [February 8, 2025, 9:58am UTC](https://discourse.julialang.org/t/task-local-storage-why-and-where/125670/4 "2025-02-08T09:58:51Z")

</div>

Thanks for both references. Based on them I was able to build an intuition on how `task_local_storage` can be used.
