# Threads.@threads over an iterator does not work - is there an reason?

**URL:** https://discourse.julialang.org/t/threads-threads-over-an-iterator-does-not-work-is-there-an-reason/71003
**Category:** General Usage
**Tags:** question
**Created:** [November 5, 2021, 12:52pm UTC](https://discourse.julialang.org/t/threads-threads-over-an-iterator-does-not-work-is-there-an-reason/71003 "2021-11-05T12:52:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)
#### Post date: [November 5, 2021, 12:52pm UTC](https://discourse.julialang.org/t/threads-threads-over-an-iterator-does-not-work-is-there-an-reason/71003/1 "2021-11-05T12:52:02Z")

</div>

```julia
julia> Threads.@threads for (index, value) in enumerate([1,2])
       end
ERROR: TaskFailedException
Stacktrace:
 [1] wait
   @ .\task.jl:322 [inlined]
 [2] threading_run(func::Function)
   @ Base.Threads .\threadingconstructs.jl:34
 [3] top-level scope
   @ .\threadingconstructs.jl:93

    nested task error: MethodError: no method matching firstindex(::Base.Iterators.Enumerate{Vector{Int64}})
    Closest candidates are:
      firstindex(::Any, ::Any) at abstractarray.jl:366
      firstindex(::Pair) at pair.jl:63
      firstindex(::UnitRange) at range.jl:567
      ...
    Stacktrace:
     [1] (::var"#36#threadsfor_fun#3"{Base.Iterators.Enumerate{Vector{Int64}}})(onethread::Bool)
       @ Main .\threadingconstructs.jl:66
     [2] (::var"#36#threadsfor_fun#3"{Base.Iterators.Enumerate{Vector{Int64}}})()
       @ Main .\threadingconstructs.jl:48

```

My current work around:

```julia
julia> Threads.@threads for (index, value) in collect(enumerate([1,2]))
       end

```

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [November 5, 2021, 1:02pm UTC](https://discourse.julialang.org/t/threads-threads-over-an-iterator-does-not-work-is-there-an-reason/71003/2 "2021-11-05T13:02:36Z")

</div>

[https://github.com/JuliaLang/julia/issues/40704](https://github.com/JuliaLang/julia/issues/40704)
