Is it safe to read from a HashSet<Int> whils...
# coroutines
c
Is it safe to read from a HashSet<Int> whilst it might be added to on another thread? specifically added as in my particular use case there is no way to remove items. I imagine each bin in the set is likely a linked list, working through it in my head and I think its safe based on these assumptions: - We assume we can have no dangling pointers we cannot remove nodes from the list - We assume we are operating on a modern cpu, and thus all word size loads are atomic meaning we couldn’t get a partial read if we accessed one of the nodes pointers whilst it was being mutated Thoughts?
e
no, it is not safe
see the notes around ConcurrentModificationException in Java's HashMap docs (which is what Kotlin's HashMap is backed by)