Created
February 17, 2026 01:14
-
-
Save skydoves/39ffd8b28650f6b72950413fc617fa08 to your computer and use it in GitHub Desktop.
SynchronizedLazyImpl - LazyThreadSafetyMode.SYNCHRONIZED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // simplified | |
| override val value: T | |
| get() { | |
| if (_value !== UNINITIALIZED_VALUE) { | |
| return _value as T // Fast path: no lock needed | |
| } | |
| return synchronized(lock) { | |
| if (_value !== UNINITIALIZED_VALUE) { | |
| _value as T // Second check inside lock | |
| } else { | |
| val typedValue = initializer!!() | |
| _value = typedValue | |
| initializer = null | |
| typedValue | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment