ConcurrentDictionary is a thread safe dictionary.
When users call GetOrAdd(TKey key, Func<TKey, TValue> valueFactory) at the same time, valuefactory will execute before the dictionary is locked due to security policy, which also means that it may be expensive due to the concurrent execution of valuefactory.
If the user can ensure that the valuefactory must be a safe code (it will not conflict with the lock inside the dictionary), can an API be provided to execute the valuefactory after the dictionary lock?
ConcurrentDictionary.GetOrAdd
ConcurrentDictionary is a thread safe dictionary.
When users call
GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)at the same time, valuefactory will execute before the dictionary is locked due to security policy, which also means that it may be expensive due to the concurrent execution of valuefactory.If the user can ensure that the valuefactory must be a safe code (it will not conflict with the lock inside the dictionary), can an API be provided to execute the valuefactory after the dictionary lock?
ConcurrentDictionary.GetOrAdd