I have a concurrent question. Suppose I have a net...
# kotlin-native
l
I have a concurrent question. Suppose I have a network IO task class with mutable state inside. Using thread pools to execute multiple network IO task instances would cause instances to be frozen in KN. If I specify a thread to each instance, the different elapsed times for each task may cause some threads to be busy and others to be idle. There is also a performance issue if you use atomic. Is there a more elegant way?
a
I would go with multiple dedicated threads, if I understood the question correctly. Having multiple threads is not a problem unless you are doing backend with thousands of threads. In this case corutines might help but they may have same issues in KN.
Atomics are also fine in many cases. Otherwise Stately may help.
k
Stately does have an alternative option, which is to keep isolated state in its own thread and communicate to it with messages. I don’t know how much state you’re talking about, or how much mutating you’re doing, so hard to comment in detail. https://github.com/touchlab/Stately#stately-isolate