开发者

ConcurrentDictionary and Disjoint Sets of Keys

开发者 https://www.devze.com 2023-03-15 17:44 出处:网络
There are 3 threads. Each of them works (reads, writes) with its own set of dictionary keys. So keys are mutually exclusive for different threads. There are also multiple threads which only read data.

There are 3 threads. Each of them works (reads, writes) with its own set of dictionary keys. So keys are mutually exclusive for different threads. There are also multiple threads which only read data.

Which of these two approaches is more efficient in terms of speed:

  1. Create a single dictionary (of type ConcurrentDictionary)
  2. Create a separate dictionary (of type ConcurrentDictionary) for each of those 3 threads.

At first glance, the 2nd approach is more efficient since there are no writer contentions. Are there any pitfalls here? If difference between two approaches is in开发者_Python百科significant then I would go with the 1st approach.


The 2nd approach is more efficient. In any case it's not a good idea to have a shared state.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号