Support multi-threaded coroutines on Kotlin/Native
See original GitHub issueYou can have multiple threads in Kotlin/Native. ~Each thread can have its own event loop with runBlocking
and have number of coroutines running there~. Currently communication between those threads via coroutine primitives (like channels) is not supported. This issue it to track enhancement of Kotlin/Native in kotlinx.coroutines
library so that all the following becomes possible:
- Launching coroutines from one thread with a dispatcher on another thread
- Await/join coroutine running on another thread
- Send/Receive elements to/from coroutines on other threads
UPDATE: Currently, coroutines are supported only on the main thread. You cannot have coroutines off the main thread due to the way the library is currently structured.
UPDATE 2: the separate library version that supports Kotlin/Native multithreading is released on a regular basis.
For the details and limitations, please follow kotlin-native-sharing.md document.
The latest version: 1.5.2-native-mt
Issue Analytics
- State:
- Created 5 years ago
- Reactions:250
- Comments:155 (66 by maintainers)
Top GitHub Comments
I suggest all users of
native-mt
builds to read the following announcement: https://blog.jetbrains.com/kotlin/2021/08/try-the-new-kotlin-native-memory-manager-development-preview/We aim to merge the support of the new MM into coroutines 1.6.0 (https://github.com/Kotlin/kotlinx.coroutines/issues/2914) and then, depending on the stability of the new MM, promote it as the default way to write concurrent code on Native platforms.
native-mt
won’t be supported as soon as the new MM is stable.📣 UPDATE: Version
1.3.7-native-mt-1.4-M2
is released — the fresh update ofnative-mt
for Kotlin1.4-M2
. For leak-free operation, this version should be used with a specially patched version of Kotlin:1.4-M2-eap-23
(it differs from stock1.4-M2
in Kotlin/Native only).This version includes fixes for additional bugs discovered by
native-mt
early adopters (thanks a lot for all of you ❤️):awaitAll
in multi-threaded scenarios (#2025)FreezingException
does not break coroutine machinery (#2064)The code is now based on the new features available in Kotlin/Native 1.4 (namely
WorkerBoundReference
) and there will be no more updates fromnative-mt
branch for Kotlin 1.3. We plan to include the code fromnative-mt
branch into the defaultkotlinx.coroutines
distribution as Kotlin/Native version of the library for upcoming Kotlin 1.4 release.