A minimal example showing this effect:
foo() = "foo"
function makebar()
sleep(rand())
res= (foo(), Base.invokelatest(foo))
@eval foo() = "bar"
res
end
fetch.(Threads.@spawn makebar() for i in 1:2)
The standard call to foo()
always returns “foo” for both threads, Base.invokelatest(foo)
returns “foo” for the thread with the shorter sleep time and “bar” for the other one.