Does .NET have a dictionary implementation that is equivalent to Java's ConcurrentHashMap?

Repeat for those .NET gurus who may not know the Java API:

ConcurrentHashMap in Java has atomic methods (i.e. do not require external locking) for general map modification operations, such as:

putIfAbsent(K key, V value)
remove(Object key, Object value)
replace(K key, V value)

It also allows iteration over a keyset without blocking (copying is required at the beginning of the iteration), and operations get()can usually alternate with calls put()without blocking (it uses the IIRC fine-grained blocking ).

Anyway, my question is: Does .NET have an equivalent dictionary implementation?

I assume that in general I would like to know if .NET has a more general set of streaming data collection libraries. Or concurrency utilities in general - equivalent to Doug Lea java.util.concurrent libraries.

+5
source share
4 answers

Not that I knew. Closest to what you are looking for is likely to be a synchronous Hashtable method that returns a (type) thread-safe wrapper around the hash table. However, it is only thread-safe for multiple authors or multiple readers. If I remember correctly, a mixture of writers and readers will not be thread safe.

+2
source

.Net 4.0 ConcurrentDictionary, GetOrAdd.

public TValue GetOrAdd(
    TKey key,
    Func<TKey, TValue> valueFactory
)

.

+16

EDIT: .NET 4, , , ConcurrentDictionary. , .NET 3.5.

ConcurrentHashMap.

concurrency -.NET , , Java Mutex, ManualResetEvent, AutoResetEvent ReaderWriterLock; (.NET 2.0) Semaphore (.NET 3.5) ReaderWriterLockSlim - , .

.NET 4.0 , concurrency. Coordination concurrency Runtime, , Microsoft Robotics Studio, , ( .NET ).

+3

, , , , , .

, "get" "put" , , . ( ) , - , .

Monitor (lock(...) . , , , .

, ReaderWriterLockSlim .., . , , .

As John notes, with the Parallel Extension, a whole new array of high-performance synchronization devices is emerging; from what I see (like here , here and here ), this is part of .NET 4.0

+2
source

All Articles