I think the issue is that fill
gets one array & re-uses it, see e.g. here: Structure Usage - #2 by mcabbott . And I guess that in mwe_fill(N)
the different threads are over-writing each other’s results.
Edit – actually, no overwriting is necessary, you get the same result without threads. mwe_comprehension(4)
simply contains sum(1:4)
, while mwe_fill(4)
contains that times the number of threads.
But the result of mwe_fill
is not safe, e.g. unique(mwe_fill(100))
has a variety of numbers, different on every run.