Description
You can have multiple threads in Kotlin/Native. Each thread can have its own event loop with . Currently communication between those threads via coroutine primitives (like channels) is not supported. This issue it to track enhancement of Kotlin/Native in runBlocking
and have number of coroutines running therekotlinx.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
Activity
brettwillis commentedon Aug 1, 2018
Do you have a ballpark time frame for implementing this (days, weeks, months, ...)? This will help me plan how to implement the first revision of our project. Thanks!
mohit-gurumukhani commentedon Aug 3, 2018
Second that. Can we please get a rough estimate?
elizarov commentedon Aug 3, 2018
We're in the design phase now. I'll update you on the status in couple of weeks.
Alex009 commentedon Oct 11, 2018
Have any progress?
elizarov commentedon Oct 11, 2018
We have a work-in-progress branch in this repo with some of the code that is implemented, but it is way too complex a change, so the work there was stopped. It is hard to get it done in the current state. We've refocused our efforts on delivering high-quality single-threaded coroutines which work really well for sharing logic between Android and iOS UI apps (I highly recommend to checkout the code of KotlinConf app here https://github.com/JetBrains/kotlinconf-app). With respect to multithreading, we'll be back to drawing board to see how this story can be made easier to code with. Don't expect results soon, though.
LouisCAD commentedon Oct 11, 2018
elizarov commentedon Oct 12, 2018
Yes, it works without
runBlocking
. The only extra effort you have to make, is you have to write a trivial UI CoroutineDispatcher for iOS. We don't include it in the library yet (that's issue #470), but you can copy-and-paste code from KotlinConf app (swift version here https://github.com/JetBrains/kotlinconf-app/blob/master/konfios/konfswift/ui/UI.swift) of from discussion in #470 (Kotlin version here #470 (comment))luca992 commentedon Oct 16, 2018
@elizarov Trying to convert Waiting for a job example to work without run blocking using (#470 (comment)) in a native macOs program. But I am still getting
There is no event loop. Use runBlocking { ... } to start one.
I think it probably is because my native program isn't starting NSRunLoop's mainloop. I can't quite figure it out.I've tried starting the loop like:
But I don't think I'm doing that correctly, any ideas?
246 remaining items