# How to deal with threadid() \<= nthreads() being not true in 1.12?

**URL:** <https://discourse.julialang.org/t/how-to-deal-with-threadid-nthreads-being-not-true-in-1-12/131473>\
**Category:** General Usage\
**Created:** [August 8, 2025, 10:11am UTC](https://discourse.julialang.org/t/how-to-deal-with-threadid-nthreads-being-not-true-in-1-12/131473 "2025-08-08T10:11:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumiya11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sumiya11/32/207147_2.png) [@sumiya11](https://discourse.julialang.org/u/sumiya11)\
**Post date:** [August 8, 2025, 10:11am UTC](https://discourse.julialang.org/t/how-to-deal-with-threadid-nthreads-being-not-true-in-1-12/131473/1 "2025-08-08T10:11:19Z")

</div>

Hello,

I recently found out that this assertion fires on 1.12.0-rc1 (seems fine on 1.11.6):

```julia
using Base.Threads
@threads for i in 1:100
    @assert threadid() <= nthreads()
end

```

Some of my code has `@threads :static` and assumes `threadid() <= nthreads()` for accessing “thread-local” buffers.

What are the options for adapting my code to the new behaviour? Should I use `nthreads(:interactive) + nthreads(:default)` as the upper bound?

PS. I read [PSA: Thread-local state is no longer recommended](https://julialang.org/blog/2023/07/PSA-dont-use-threadid/). I have still been using `@threads :static` because it’s simple.

PS. Originally discovered in [moving tests for rational functions to the subfolder · SciML/StructuralIdentifiability.jl@ebfeeab · GitHub](https://github.com/SciML/StructuralIdentifiability.jl/actions/runs/16625267235/job/47236173687?pr=432)

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [August 8, 2025, 10:12am UTC](https://discourse.julialang.org/t/how-to-deal-with-threadid-nthreads-being-not-true-in-1-12/131473/2 "2025-08-08T10:12:50Z")

</div>

> [@sumiya11](#):
>
> PS. I read [PSA: Thread-local state is no longer recommended](https://julialang.org/blog/2023/07/PSA-dont-use-threadid/). I have still been using `@threads :static` because it’s simple.

Using `:static` is fine, assuming specific values for `threadid` is where the issue lies.

In particular, with thread adoption the number of OS threads may change over the course of execution. Don’t use `threadid` as an index.
