Skip to content

GetOrAdd is not thread safe which is counter intuitive #7704

@yepeekai

Description

@yepeekai

I expect the concurrentDictionary to be thread safe for all of its write operation. The documentation of the GetOrAdd method doesn't specify that it is not thread safe which is a problem. I really think that there should be a GetOrAdd overload with a bool specifying that we want thread safety. I also think that the current GetOrAdd should be renamed GetOrAddUnsafe to make it clear that it doesn't respect the expected behavior of the class


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

  • ID: 806c6485-9396-e6bf-2f8e-f27866115626
  • Version Independent ID: 3e499bf3-fa82-0b82-5d85-84a0b3fe0515
  • Content: ConcurrentDictionary<TKey,TValue> Class (System.Collections.Concurrent)
  • Content Source: [xml/System.Collections.Concurrent/ConcurrentDictionary2.xml](https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System.Collections.Concurrent/ConcurrentDictionary2.xml)
  • Product: dotnet-api
  • GitHub Login: @mairaw
  • Microsoft Alias: mairaw

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions