Is the fact that closed-over vars are volatile documented anywhere? I thought I had read all the docs and don’t recall reading anything like that.
I find it to be highly unlikely that anyone knowingly decided to write lock-free code and specifically chose to rely on this, given the obscure nature of it and the fact that it’s not at all obvious from reading the code that it’d be correct! I actually do use volatile sometimes, usually to avoid bothering with an AtomicReference class, but I wouldn’t have expected the compiler to work this way.