I'm on JVM, I have two coroutines that needs to ac...
# coroutines
f
I'm on JVM, I have two coroutines that needs to access a mutable state exclusively. I can choose between using
synchronized
or a
Mutex
. Both work. Which one should I use? On one side,
synchronized
can block the thread of a coroutine but it's much faster, on the other side
Mutex
never blocks the thread but it's slower. Is there a preferred option, in general? Thanks
c
You could also use a
MutableStateFlow
, which uses
synchronized
under the hood.