-
Notifications
You must be signed in to change notification settings - Fork 11
FL0011
bagley2014 edited this page Oct 22, 2021
·
1 revision
GetOrAddValue
is not threadsafe and should not be used with ConcurrentDictionary
; use GetOrAdd
instead.
GetOrAddValue
is a Faithlife utility function that uses Add
but doesn't use locks. This means it isn't safe for multithreading, even if you're calling it on a ConcurrentDictionary
. In contrast, ConcurrentDictionary
contains a GetOrAdd
function that behaves well in multithreaded code (see here for details).
Consequently, GetOrAdd
should be preferred over GetOrAddValue
for ConcurrentDictionary
.