# Enumerate not suported for @threads

**URL:** <https://discourse.julialang.org/t/enumerate-not-suported-for-threads/37670>\
**Category:** Julia at Scale\
**Tags:** multithreading\
**Created:** [April 15, 2020, 11:07pm UTC](https://discourse.julialang.org/t/enumerate-not-suported-for-threads/37670 "2020-04-15T23:07:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Post date:** [April 15, 2020, 11:07pm UTC](https://discourse.julialang.org/t/enumerate-not-suported-for-threads/37670/1 "2020-04-15T23:07:35Z")

</div>

When trying to use @threads on a for loop with enumerate, an error is thrown

```julia
Threads.@threads for (idx, a) in enumerate(A)
    ... # Process
end

```

```julia
ERROR: LoadError: TaskFailedException:
MethodError: no method matching firstindex(::Base.Iterators.Enumerate{Array{Int64,1}})

```

Is there something I should be aware of, or a workaround? Or is this a bug in Julia?

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [April 16, 2020, 1:07am UTC](https://discourse.julialang.org/t/enumerate-not-suported-for-threads/37670/2 "2020-04-16T01:07:57Z")

</div>

Try replacing with `collect(enumerate(A))` instead. Its just that `@threads` doesn’t work with generic iterables like the output of `enumerate`, it needs some concrete array-like thing which has a `length` and `firstindex`.

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [April 16, 2020, 3:04am UTC](https://discourse.julialang.org/t/enumerate-not-suported-for-threads/37670/3 "2020-04-16T03:04:28Z")

</div>

FYI, [`ThreadsX.foreach`](https://tkf.github.io/ThreadsX.jl/dev/#ThreadsX.foreach) supports `enumerate`

```julia
ThreadsX.foreach(enumerate(A)) do (idx, a)
    ... # Process
end

```
