Closed
Description
The following is from the Kotlin coroutine docs:
Coroutines ARE light-weight
Run the following code:
import kotlinx.coroutines.*
fun main() = runBlocking { repeat(100_000) { // launch a lot of coroutines launch { delay(1000L) print(".") } } }
It launches 100K coroutines and, after a second, each coroutine prints a dot.
Now, try that with threads. What would happen? (Most likely your code will produce some sort of out-of-memory error)
What happens is that it does not crash. (I'm using MacOS 10.15.5 on a 2020 13" MacBook Pro.)
The delay and/or coroutine count should be increased in the example code.