javakotlinjvmkotlin-coroutinesgreen-threads

How Kotlin coroutines will use Project Loom?


Right now, Kotlin coroutines are implemented without help of JVM. It does not use something like green (virtual) threads. You can read about implementation of coroutines here - https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md#implementation-details

In the near future (like, 1-2 year), project Loom (implementation of green threads in JVM) will be released. You can read details about it here - http://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html

So, will Kotlin use these virtual threads as compilation backend? Or there are some reasons, why it is not possible? I talk about JVM target with needed version (it is obvious, that we need own implementation for android).

Actually, there is more general question. Do we really need Kotlin coroutines, when Project Loom will be released?


Solution

  • As Roman Elizarov outlined in his talk there will be interoperation with Project Loom.

    As for the need for coroutines, you have to realize that Kotlin is a multiplatform language which means that coroutines have to work on all platforms, including the browser and native code.

    Even if they will use Project Loom on the JVM the API has to stay consistent, since the same code will be compiled to all platforms.