# Trying to make multithreading to work on applying a function number of times

**URL:** <https://discourse.julialang.org/t/trying-to-make-multithreading-to-work-on-applying-a-function-number-of-times/103124>\
**Category:** Performance\
**Tags:** multithreading, speed-optimization\
**Created:** [August 23, 2023, 6:05pm UTC](https://discourse.julialang.org/t/trying-to-make-multithreading-to-work-on-applying-a-function-number-of-times/103124 "2023-08-23T18:05:08Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [August 24, 2023, 7:33am UTC](https://discourse.julialang.org/t/trying-to-make-multithreading-to-work-on-applying-a-function-number-of-times/103124/9 "2023-08-24T07:33:54Z")

</div>

You are almost there.

Unfortunately, the use of `Threads.threadid()` is no longer recommended due to the dynamical scheduling mechanisms that `Threads.@threads` offers.

You can read more about here [PSA: Thread-local state is no longer recommended; Common misconceptions about threadid() and nthreads()](https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274).

* * *

To get the version you have working, you have to update the for loop to read

```julia
Threads.@threads :static for i in 1:50

```

However, as the blog post explains this is also not longer recommended and one should use the advises given there.

---

_[View the full topic](https://discourse.julialang.org/t/trying-to-make-multithreading-to-work-on-applying-a-function-number-of-times/103124)._
