Hi, I have a question regarding `LazyThreadSafetyM...
# kotlin-native
k
Hi, I have a question regarding
LazyThreadSafetyMode
. I see in the documentation that it explicitly says "no locks are used" for
NONE
and "locks are used" for
SYNCHRONIZED
but it's not explicit about whether or not there is locking for
PUBLICATION
. Is it the case that
PUBLICATION
doesn't use locking underneath and instead just lets more than one thread attempt the initialization without blocking? It's just that the first returned value "wins" and is shared with all threads? This was my takeaway from the documentation but I just wanted to double check.
a
Do not know how this is implemented, but on the JVM is does what is says on the tin: The first thread to retrieve the value also initializes it as well. On the JVM it uses a lock free algorithm.
🙏 1
k
I just found it confusing that the docs explicitly call out “locks” and “no locks” for Synchronized and None. Thanks for confirming!