I noticed in the docs that threads aren't supporte...
# kotlin-native
m
I noticed in the docs that threads aren't supported in kotlin/native; Is there an example on background tasks that can be started once and stopped once, and keep updating an array for the entire duration they're active for?
t
you can do this with a
Worker
m
From what I could tell those used more of a futures-like approach, while I'm looking more for a background thread
r
If you're using the new native memory manager and a recent version of coroutines, you can do this pretty much the same way you would with coroutines on the jvm
m
Do you have an example? It should be noted that due to this being an exposed API, it has to be able to be called from a blocking context
m
FWIW, you can do
pthread_create()
on native
k
You can also block on a worker waiting for a result, but in coroutines you can run blocking. If the call is blocking, though, what's the goal of a background thread? Just curious.
a
And regardless of the memory model and coroutines versions, it is also possible with Reaktive, which has been supporting multi-threading in K/N for several years.
m
You can also block on a worker waiting for a result, but in coroutines you can run blocking. If the call is blocking, though, what's the goal of a background thread? Just curious.
The background thread would continuously monitor a process and update an array, and the blocking code would get the value of that array at certain intervals.