Is it defined behavior to modify `iter` while `for`-looping over it?

I re-thought about this problem.

In my original code, there is a main task that updates snap (via snap = k_th_NEW_OBJECT) iteratively, while at the same time distribute snap to other many subproblem tasks via
@spawn subproblem_duty(j, snap).

So this is a one-thread write, multiple other threads read async program.

The disquieting fact is that while I think snap = k_th_NEW_OBJECT is just a re-labeling action which can be finished instantly. (So I didn’t even use any locks.) The real underlying code julia execute is actually a mutation
Core.setfield!(snap, :contents, k_th_NEW_OBJECT).

So my concept about re-labeling turns out to be an illusion.

Nevertheless, the upside is: when I did a test to see if the other reading threads can receive false data (which is theoretically possible), I do not see any false data. In other words, my worry is not occurring in practice.

import Random.seed! as seed!
N::Int = 999
function gen(cnt)
    if cnt % 2 == 1
        seed!(1)
        a = rand(Int128, N, N);
        b = rand(Int128, N, N);
        c = rand(Int128, N, N);
        d = rand(Int128, N, N);
        e = rand(Int128, N, N);
        f = rand(Int128, N, N);
        return (; a, b, c, d, e, f)
    else
        seed!(7)
        a = rand(Int128, N, N);
        b = rand(Int128, N, N);
        c = rand(Int128, N, N);
        d = rand(Int128, N, N);
        e = rand(Int128, N, N);
        f = rand(Int128, N, N);
        return (; a, b, c, d, e, f)
    end
end;
function check(s)
    if s == gen(0)
        println(0)
    elseif s == gen(1)
        println(1)
    else # I cannot see this in practice
        println("\tEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE")
    end
end;

function test(m)
    for c = 1:10000000
        for j = 1:14
            Threads.@spawn check(m)
        end
        println("c=$c")
        m = gen(c) #  Core.setfield!(m, :contents, %51)
    end
end

test(gen(0))