<p dir="auto">Since it is possible to select subranges of iterators using UnitRange objects it is my opinion that Threads.<a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/threads/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/threads">@threads</a> should use that instead of the iteration through the subrange and item-wise evaluation of the given range at a specific index. See <a href="https://github.com/JuliaLang/julia/blob/7cdb7793e007229b139c4b0d575c20d75d792765/base/threadingconstructs.jl#L52">threadingconstructs.jl#L52</a>.</p>
<p dir="auto">Solution: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="178116391" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/18604" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/18604/hovercard" href="https://github.com/JuliaLang/julia/pull/18604">#18604</a></p>
<p dir="auto">This becomes relevant when you want to use CartesianRange for parallelised ndimensional loops. CartesianRange flat representation is well defined so selecting subranges (<a href="https://groups.google.com/forum/#!topic/julia-users/uFAqu31gHq4" rel="nofollow">inspiration</a>) using indices of the flat representation is well defined, therefore: they can be split into subranges without any problems. Using that ndimensional loops can be generically parallelised.</p>
<p dir="auto">On the master branch, it looks like neither of these currently works,</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; @Threads.threads for (i,j) in [(1,2),(3,4)]
           i
       end
ERROR: syntax: invalid syntax in &quot;local&quot; declaration"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">@Threads</span><span class="pl-k">.</span>threads <span class="pl-k">for</span> (i,j) <span class="pl-k">in</span> [(<span class="pl-c1">1</span>,<span class="pl-c1">2</span>),(<span class="pl-c1">3</span>,<span class="pl-c1">4</span>)]
           i
       <span class="pl-k">end</span>
ERROR<span class="pl-k">:</span> syntax<span class="pl-k">:</span> invalid syntax <span class="pl-k">in</span> <span class="pl-s"><span class="pl-pds">"</span>local<span class="pl-pds">"</span></span> declaration</pre></div>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; @Threads.threads for i=1:2, j=3:4
           i
       end
ERROR: syntax: invalid assignment location &quot;i=1:2&quot;"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">@Threads</span><span class="pl-k">.</span>threads <span class="pl-k">for</span> i<span class="pl-k">=</span><span class="pl-c1">1</span><span class="pl-k">:</span><span class="pl-c1">2</span>, j<span class="pl-k">=</span><span class="pl-c1">3</span><span class="pl-k">:</span><span class="pl-c1">4</span>
           i
       <span class="pl-k">end</span>
ERROR<span class="pl-k">:</span> syntax<span class="pl-k">:</span> invalid assignment location <span class="pl-s"><span class="pl-pds">"</span>i=1:2<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">I think this might be low hanging enough fruit that even I could figure it out. Would a PR adding this functionality be something the developers are interested in?</p>