Is it safe to use AtomicLong inside coroutines? I ...
# coroutines
m
Is it safe to use AtomicLong inside coroutines? I have the following code:
Copy code
fun a() {
    Log.i("Log info")
        launch {
            myAtomicLong.set(SystemClock.elapsedRealtime()) 
            Log.i("Log info in launch")
        }
}
The second Log.i never gets executed. It’s inside a class implementing coroutineScope on Dispatchers.IO. The AtomicLong is used in multiple of those launch blocks.
m
Maybe scope is alrady cancelled? Does it execute if you comment out atomic call?
o
as safe as in Java, Kotlin coroutines do not impose more restrictions to Java threads
m
I think you are correct about the cancelled scope, the job has a parent that might call cancelChildren() which then would make all the launches useless (🤦‍♂️ <- me)