i want to use kotlin native with concurrency featu...
# kotlin-native
t
i want to use kotlin native with concurrency feature. i wrote a code like this:
Copy code
@ExperimentalForeignApi
fun main() {
    // Start a new worker
    val worker = Worker.start()

    // Schedule a task for execution on the worker
    worker.execute(TransferMode.SAFE, {}) {
        // Print the thread identifier of the current thread
        println("Hello from a background worker!")
    }

    // request termination of the worker
    worker.requestTermination(true).result
}
but i got a warning message like this:
Main.kt:11:20 Workers API is obsolete and will be replaced with threads eventually
so, where's the documentation about new "threads" API?
e
I don't believe there is yet but you can use
kotlinx.coroutines
2
a
you can still use Workers, the warning is only there to indicate that they will be replaced... eventually
Workers continue being supported and maintained, but they eventually will be replaced with threads API and then deprecated.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.native.concurrent/-obsolete-workers-api/
t
ah,, okay. i understood.
l
You can also just start threads using
pthread_create
. It's a POSIX API, so it's not Kotlin specific.