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

<div class="post-metadata">

**Author:** ![Chong\_Wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chong_wang/32/20307_2.png) [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Post date:** [July 8, 2023, 11:58pm UTC](https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274/40 "2023-07-08T23:58:29Z")

</div>

> [@vchuravy](#):
>
> Within a process `myid()` is stable, whereas within a task `threadid()` might not be.

Suppose I have 10 calculations distributed in 5 workers, and now worker 2 is running task 1. Isn’t it possible that calculation 1 yields and calculation 6 kicks in in worker 2 before task 1 finishes? That will cause a problem even if `myid()` is stable.

Or is it something like `@spawnat p expr` does not wrap `exp` in a task and will never yield before `expr` finishes?

---

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