`mutableXOf` are not thread safe right? I have a m...
# coroutines
a
mutableXOf
are not thread safe right? I have a mutable set which i populate from within multiple coroutines (thousands) and I am missing some items after my code is executed. I wrapped the
.add
calls from a single thread context scope and it seems to be working fine now. are there any thread safe versions of mutable set of? or better yet, are there any recommended approaches to this?
👌 1
d
There are the Java standard library thread-safe data structures on the JVM, but not on Native, of course. In most cases, the code can be structured cleanly so that only one coroutine accesses the data structure (though it's not always possible by far). It's the recommended approach.
m
I guess this question goes in the same direction. Maybe the thread contains some useful answers. https://kotlinlang.slack.com/archives/C3PQML5NU/p1757122073618069
a
thanks both. good pointers