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:
- Create a single dictionary (of type ConcurrentDictionary)
- 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.
精彩评论