# Why has simple threading using \`threadid\` become so complex in v1.12...?

**URL:** <https://discourse.julialang.org/t/why-has-simple-threading-using-threadid-become-so-complex-in-v1-12/129135>\
**Category:** Performance\
**Created:** [May 19, 2025, 9:09am UTC](https://discourse.julialang.org/t/why-has-simple-threading-using-threadid-become-so-complex-in-v1-12/129135 "2025-05-19T09:09:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 19, 2025, 9:28am UTC](https://discourse.julialang.org/t/why-has-simple-threading-using-threadid-become-so-complex-in-v1-12/129135/2 "2025-05-19T09:28:45Z")

</div>

> [@Datseris](#):
>
> ```julia
> # setup
> ds = mutable_datastructure()
> dss = [deepcopy(ds) for _ in 1:Threads.nthreads()]
> outputs = zeros(length(some_iterable))
> 
> # pre v1.12 way:
> Threads.@threads for j in some_iterable
> i = Threads.threadid()
> ds = dss[i]
> outputs[j] = computation!(ds, j)
> end
> 
> ```

I would write this as

```julia
using OhMyThreads
outputs = @tasks for j in some_iterable
    @set collect=true # makes this into a `map`-like operation
    @local ds = mutable_datastructure() # Creates 1-instance of your mutable data structure per task
    computation!(ds, j)
end

```

> [@Datseris](#):
>
> I guess my question is why couldn’t we make the first version work in v1.12 just out of the box?

For what it’s worth, what you were doing was incorrect long before v1.12, it’s just that it broke even more with 1.12. There’s a blogpost about this here that explains why uses of `threadid` like this cause race conditions. [PSA: Thread-local state is no longer recommended](https://julialang.org/blog/2023/07/PSA-dont-use-threadid/). It should really be updated to mention OhMyThreads.jl though

---

_[View the full topic](https://discourse.julialang.org/t/why-has-simple-threading-using-threadid-become-so-complex-in-v1-12/129135)._
