I'm looking at the source code for the atomics. I ...
# kotlin-native
s
I'm looking at the source code for the atomics. I think I must be confused about the way that frozen objects work:
Copy code
@Frozen
class AtomicInt(private var value: Int = 0) {
  // ...
}
If you have a
var
in a frozen object, how can you still mutate the value of that
var
? I thought it was unchangeable after it is frozen. What am I misunderstanding?
o
Here
frozen
is not the same as
immutable
, more like
mutable using concurrency-safe APIs
1
s
@olonho IC.
frozen
doesn't enforce the use of concurrency safe APIs though, does it (how would it?)? It seems like it's still very easy to have race conditions with
frozen
. If I'm now seeing the whole picture, I now don't understand how Kotlin/native's threading model is an improvement over Java. If I mark something as
frozen
, it seems like I can have shared mutable state between threads just as easily as I do in Java. What am I missing? How is Kotlin/native's threading model an improvement over Java if that's the case?
o
On regular objects
frozen
means immutable wrt regular field modifications,
Atomic[Int|Long|Reference]
are intentional exception to that rule, as atomic values API allows concurrency-safe modification.
s
oh, ok, that makes more sense. I was looking at the source code to try and understand how that exception was made, so I guess the compiler knows about those classes explicitly.