Viktor Qvarfordt
05/13/2019, 11:06 PMbdawg.io
05/13/2019, 11:15 PMGlobalScope is not the same as the scope provided by runBlocking.
Your runBlocking parent scope only has the main thread, so only one coroutine will run at a time accessing the counter from the same thread, so there's no shared mutable state going on.
GlobalScope, on the other-hand, has multiple threads available to it, which means multiple of your `massiveRun`'s job will run in parallel, causing overwriting of mutable statebdawg.io
05/13/2019, 11:16 PMrunBlocking {
launch(Dispatchers.Default) {
// paste the function body
}.join()
}Viktor Qvarfordt
05/13/2019, 11:17 PMbdawg.io
05/13/2019, 11:18 PMrunBlocking {
withContext(Dispatchers.Default) {
// paste the function body
}
}bdawg.io
05/13/2019, 11:18 PMViktor Qvarfordt
05/13/2019, 11:20 PMlouiscad
05/14/2019, 5:51 AMsuspend fun main(): Unit = coroutineScope { … }? It uses Dispatchers.Default.bdawg.io
05/14/2019, 4:40 PMlouiscad
05/14/2019, 4:46 PMThread.sleep failed to show any difference with `delay`… It was the first I used it as it was new in 1.3RC. I natively thought it'd be like runBlocking. Found the answer and fixed it during Q&A, fortunately.