that can be safely used when accessed from multiple `suspend fun`s? We’re seeing unpredictable behavior, where keys that should exist don’t.
ConcurrentHashMap
displays the same behavior as
mutableMapOf()
in our case.
j
Joffrey
07/07/2023, 4:31 PM
ConcurrentHashMap
only makes its own operations atomic, but if your own business logic needs to have atomic sections, you might have to use a
Mutex
manually. Could you please share a piece of code reproducing your problem?
m
Matthew Adams
07/07/2023, 4:32 PM
Not really, very far down in the weeds in customer’s code
c
CLOVIS
07/10/2023, 10:27 AM
It depends what your definition of "safely" is.
If you write this:
Copy code
map[5] = someTransformation(map[5])
then you always have a risk two concurrent executions will corrupt each other, no matter the type of map you use.
In these cases, the only thing you can do is use a Mutex everywhere