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

<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 6, 2023, 10:49pm UTC](https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274/9 "2023-07-06T22:49:11Z")

</div>

> [@lmiq](#):
>
> I think this is perfectly fine, because you are not using the function `threadid()`. You can call that `ichunk` to avoid confusion and there will be no concurrency issues there.

ugh yeah I did not read that code carefully enough, yeah it looks like it’s fine, sorry about the mixup @jgreener64.

Maybe I should take this opportunity to point out that reasoning about race conditions and multi-threading is really hard! That’s why we should be aiming to write code that doesn’t depend on the low-level details of multithreading.

I think the whole idea of setting up state before a loop that a threaded loop then mutates is just generally a bad idea and we should have abstractions that avoid it. Humans are not particularly good at eyeballing some code and saying “yeah that’s safe” or “nah that’s unsafe”

---

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