You are maybe having a race condition do to the model
variable (and others) assignment outside the @threads
loop. That can cause a thread to use a model that is not optimize!
yet as pointed out by @odow.
That could explain also this:
It can be fixed (I think) in your MWE
making the model asigment inside the @threads
loop local
function run_modelthreading(;α=0.05)
[...]
# This make all this variables visibles between all threads
model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
[...]
Threads.@threads for i in 1:n
[...]
# This will force this variables to be local for each thread
local model, x, y, γ = build_model(FutureValue,Loss,Demand,nproducts,prob,nscen,α)
[...]
end
return [...]
end