Do Kotlin coroutines provide any "happens-before" guarantees?
For example, is there "happens-before" guarantee between write to mutableVar and subsequent read on (potentially) other thread in this case:
suspend fun doSomething() {
var mutableVar = 0
withContext(Dispatchers.IO) {
mutableVar = 1
}
System.out.println("value: $mutableVar")
}
Edit:
Maybe additional example will clarify the question better becuase it's more Kotlin-ish (except for mutability). Is this code thread-safe:
suspend fun doSomething() {
var data = withContext(Dispatchers.IO) {
Data(1)
}
System.out.println("value: ${data.data}")
}
private data class Data(var data: Int)