# Question about @threads

**URL:** <https://discourse.julialang.org/t/question-about-threads/25404>\
**Category:** General Usage\
**Created:** [June 18, 2019, 11:48am UTC](https://discourse.julialang.org/t/question-about-threads/25404 "2019-06-18T11:48:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [June 18, 2019, 11:48am UTC](https://discourse.julialang.org/t/question-about-threads/25404/1 "2019-06-18T11:48:51Z")

</div>

I have some workload and want to work on it using all threads. If I do

```julia
Threads.@threads for _ in 1:nthreads()
    # doit
end 

```

Is it guaranteed, that all threads are used, or could it be that one thread occurs multiple times?  
For instance does the following always hold:

```julia
using Base.Threads: threadid, nthreads, @threads
ret = fill(-1, Threads.nthreads())
@threads for _ in 1:nthreads()
    ret[threadid()] = threadid()
end
@test ret == 1:nthreads()

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 18, 2019, 12:12pm UTC](https://discourse.julialang.org/t/question-about-threads/25404/2 "2019-06-18T12:12:45Z")

</div>

No that will not be guaranteed whether or not the current implementation has this property.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 19, 2019, 2:21pm UTC](https://discourse.julialang.org/t/question-about-threads/25404/3 "2019-06-19T14:21:52Z")

</div>

Actually, I just realized that the bandaid I put in there for nested threaded loop is still there (I thought is is gone with the merge of the partr branch but apparently not…) so no the current implementation does not have such a property either.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [June 19, 2019, 7:17pm UTC](https://discourse.julialang.org/t/question-about-threads/25404/4 "2019-06-19T19:17:50Z")

</div>

Thanks for the clarification!
