# PSA: Thread-local state is no longer recommended; Common misconceptions about threadid() and nthreads()

**URL:** <https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274>\
**Category:** General Usage\
**Tags:** announcement, multithreading\
**Created:** [July 6, 2023, 6:12pm UTC](https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274 "2023-07-06T18:12:08Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [July 8, 2023, 4:58am UTC](https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274/26 "2023-07-08T04:58:08Z")

</div>

`task_local_storage` isn’t going anywhere. It’s just not particularly useful or nice for implementing reductions.

For an example of something that `task_local_storage` does well in the context of `@threads`, here’s some code @GunnarFarneback shared on Zulip:

```julia
Threads.@threads for j in axes(x, 2)
    temp = get!(() -> Vector{Int}(undef, N), task_local_storage(), :temp)::Vector{Int}
    # fill in temp with j-dependent data
    for i in axes(x, 1)
        y[i, j] = # some computation with x, i, j, temp
    end
end

```

---

_[View the full topic](https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274)._
