Does `@ThreadLocal` annotated property gets alloca...
# kotlin-native
a
Does
@ThreadLocal
annotated property gets allocated for every thread everytime a new thread is created or when it is accessed for the first time?
a
Perhaps you can println from the init section and check 😀
a
How'd I able to confirm if I will access the property?
a
Ahh, the property. Thought about objects. Maybe a delegated property would help with printing?
Or calculate the value using function with println
k
@ThreadLocal doesn't apply to properties to my knowledge
a
Top level properties? should work
k
sure, for top level properties
k
I'm pretty sure it happens when the new thread is created and would need to be lazy for doing so on access, but not sure. Could you not do something like @Arkadii Ivanov suggested? make a simple class that prints in init and have that type as the property, then maybe sleep the thread before accessing it? I think it would be pretty simple to test.
Much earlier on, all top levels were thread local. If you created a
Worker
at top level, that would create a thread for the worker, which would create another top level
Worker
, which would create another thread, and repeat until it crashed or you shut it down. I'm 99% sure that's why all top levels are treated special (main thread only).
a
😮