Is it possible to share a HashMap between threads without locking the entire HashMap?

前端 未结 3 1381
时光说笑
时光说笑 2021-02-13 05:23

I would like to have a shared struct between threads. The struct has many fields that are never modified and a HashMap, which is. I don\'t want to lock the whole

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-13 05:59

    Maybe you want to consider rust-evmap:

    A lock-free, eventually consistent, concurrent multi-value map.

    The trade-off is eventual-consistency: Readers do not see changes until the writer refreshes the map. A refresh is atomic and the writer decides when to do it and expose new data to the readers.

提交回复
热议问题