Overhead of `Threads.@threads`

@mcabbott Would something like the following work?

julia> module Bar

       macro threaded(expr)
           esc(quote
               if Threads.nthreads() == 1
                   $(expr)
               else
                   Threads.@threads $(expr)
               end
           end)
       end

       end

Using nested macros seems to be complicated in Julia, cf. Macro hygiene is hard to use correctly in nested macro expansion · Issue #37691 · JuliaLang/julia · GitHub. I’m not an expert in writing macros, so every input is appreciated.