Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the different between native-mt and normal kotlin coroutine lib?

When we use coroutine, we can either have the normal kotlin coroutine or the native-mt version.

i.e.

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'

or

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-native-mt'

Is there any difference between them? When should we use which?

like image 959
Elye Avatar asked Jun 06 '21 07:06

Elye


People also ask

How many types of coroutines are in Kotlin?

Basically, there are two types of Coroutines: Stackless. Stackful.

Is Kotlin multi threaded?

Multithreaded coroutines A special branch of the kotlinx. coroutines library provides support for using multiple threads. It is a separate branch for the reasons listed in the future concurrency model blog post. However, you can still use the multithreaded version of kotlinx.

Is KTOR multithreaded?

coroutines for Kotlin/Native was single-threaded. You could suspend execution, but not schedule work on different threads. This was due to Kotlin/Native's memory model. Ktor was designed to run on this single-threaded model.

Are Kotlin coroutines parallel?

Kotlin's Coroutines enabling you to write parallel code easily, in a sequential way, and without worrying about the contextual overheads you know from using threads in Java.


1 Answers

It basically provides capability to use multiple threads in Kotlin/Native code (typically as part of a Kotlin Multiplatform (KMP) project). Some more info at https://kotlinlang.org/docs/mobile/concurrency-and-coroutines.html#multithreaded-coroutines. This is also version used now by many KMP libraries (e.g. Ktor) and is generally a requirement when developing KMP apps.

like image 184
John O'Reilly Avatar answered Sep 28 '22 04:09

John O'Reilly