T () { while (true) { T value = myValueRef.get(); if (value != null) return value; // value already computed and cached final NotNullComputable<T> computable = myComputable; if (computable == null) continue; // computable is null only after some thread succeeds CAS RecursionGuard.StackStamp stamp = RecursionManager.markStack(); value = computable.compute(); if (stamp.mayCacheNow()) { if (myValueRef.compareAndSet(null, value)) { // try to cache value myComputable = null; // if ok, allow gc to clean computable return value; } // if CAS failed then other thread already set this value => loop & get value from reference } else { return value; // recursion detected } } }