World Age Problem Explanation

If you want to just demonstrate the basic world age behavior, you don’t need threads or anything, you just evaluate a new function definition in the same local scope before calling it:

f() = 1
function g()
    @eval f() = 2
    f()
end

If you call g once it will return 1, if you call it again it will return 2. If you do this instead:

f() = 1
function g()
    @eval f() = 2
    Base.invokelatest(f)
end 

This will return 2 every time you call it.

34 Likes