See No more 1st class support for Threads? [thread-local storage] - #34 by foobar_lv2
Also note that if one does not need to store the task-local buffer and does not need the indices, this can be simplified to:
model = fit(Model, data)
# split work in n=nthreads() chunks
@threads for chunk in ChunkSplitters.chunks(1:1000; n=Threads.nthreads())
m = deepcopy(model)
for item in chunk
predict!(m, newdata)
end
end
Which makes pretty clear that the only n
copies of model
are created, and that there is not race condition among their uses.