Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is .freeze() in Kotlin/Native?

I see yet another function in Kotlin/Native, that does not exist in the Kotlin JVM or JS. What does it?

like image 696
Eugene Petrenko Avatar asked Sep 03 '18 09:09

Eugene Petrenko


1 Answers

From Kotlin native's Concurrency docs

Freezing is a runtime operation making given object subgraph immutable, by modifying the object header so that future mutation attempts lead to throwing an InvalidMutabilityException. It is deep, so if an object has a pointer to another objects - transitive closure of such objects will be frozen. Freezing is the one way transformation, frozen objects cannot be unfrozen. Frozen objects have a nice property that due to their immutability, they can be freely shared between multiple workers/threads not breaking the "mutable XOR shared" invariant.

like image 112
Vincent Paing Avatar answered Oct 07 '22 00:10

Vincent Paing