Re:Why Hashbrown Does a Double Lookup
by shittyadmin on Thursday March 21, 2019 @12:18PM
(#19454071)
But you don't need to write every time, only on occasion, so you can actually use a read write lock and in the nominal case many threads can read just fine.
That said, it's probably still better to avoid this unless it's absolutely necessary to modify the underlying structure sometimes, I recently had to do this for an LRU cache.
Right. And in Rust implementing the hash table that way will suddenly make the table no longer flagged as "Sync" by the compiler, so you will be unable to share it between threads.
As soon as your reads can modify the internal state of the data structure, it might modify the state in a way which trips up another read; so you can no longer have many threads reading the data structure at once.