Minimal-locking thread-safe hashtable?

白昼怎懂夜的黑 提交于 2021-02-08 14:19:21

问题


Are there any available implementations of a Hashtable that provide thread safety with minimal locking in .NET? Or in another language that can be ported to .NET?

We're looking for something in between using a BCL Dictionary<,> class with lock() and a distributed caching application like memcached or Velocity.

The intended use is for a cache with thousands of readers reading out immutable values based on keys (either numbers or guids, we haven't decided which yet). There will be far less writers, possibly only one.


回答1:


Starting in .Net 4.0 there is ConcurrentDictionary. This is a hashtable style structure meant for high performance use between multiple threads.

Details on it's use and implementation can be found here:

  • http://blogs.msdn.com/pfxteam/archive/2010/01/08/9945809.aspx



回答2:


In What's the best way of implementing a thread-safe Dictionary? Brian Rudolf shares a link to a thread-safe dictionary that uses ReaderWriterLockSlim: http://devplanet.com/blogs/brianr/archive/2008/09/26/thread-safe-dictionary-in-net.aspx.

You might also look at the Synchronized Hashtable: http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx.



来源:https://stackoverflow.com/questions/2111030/minimal-locking-thread-safe-hashtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!