doodla
11/18/2020, 8:18 PMvar x: Int = 0
suspend fun modifyX() {
if (x > 10) {
x -= 1
} else {
x += 1
}
}
fun main() {
runBlocking {
withContext(<http://Dispatchers.IO|Dispatchers.IO>){
repeat(10) {
modifyX()
}
}
}
}
Does x
need to be @Volatile
?Zach Klippenstein (he/him) [MOD]
11/18/2020, 8:19 PMdoodla
11/18/2020, 8:20 PMsuspend
function modifying an integer variable. Should this variable be synchronized?Zach Klippenstein (he/him) [MOD]
11/18/2020, 8:52 PMdoodla
11/18/2020, 9:44 PMZach Klippenstein (he/him) [MOD]
11/18/2020, 9:48 PMdoodla
11/18/2020, 9:48 PM