kevin.cianfarini
03/20/2020, 3:20 PMsuspend fun foo() = withContext(Dispatchers.Default) {
for (1..100) {
async { ... }
}
}
Will that be bound to a single thread or will is try to spread the workload?streetsofboston
03/20/2020, 3:27 PMDefault
is backed by a thread pool of more than one thread), but i don’t think the exact number of parallel threads is guaranteed.kevin.cianfarini
03/20/2020, 3:27 PMZach Klippenstein (he/him) [MOD]
03/20/2020, 3:33 PMIt is backed by a shared pool of threads on JVM. By default, the maximal level of parallelism used by this dispatcher is equal to the number of CPU cores, but is at least two. Level of parallelism X guarantees that no more than X tasks can be executed in this dispatcher in parallel.
On JS, there are no threads, and this dispatcher is just backed by the JS event loop, which is not parallelized.kevin.cianfarini
03/20/2020, 3:39 PMlouiscad
03/20/2020, 4:06 PMkevin.cianfarini
03/20/2020, 4:20 PMlouiscad
03/20/2020, 4:44 PMkevin.cianfarini
03/20/2020, 5:22 PMlouiscad
03/20/2020, 5:59 PMA Default dispatcher on Kotlin/Native contains a single background thread
kevin.cianfarini
03/20/2020, 6:00 PMlouiscad
03/20/2020, 6:01 PMkevin.cianfarini
03/20/2020, 6:03 PM