Skip to content

Add System.Collections.Concurrent.ConcurrentHashSet<T> #15326

Closed

Description

@daveaglick

We already have classes in the System.Collections.Concurrent namespace that provide (mostly) equivalent APIs to most of those in the System.Collections.Generic namespace. However, one omission is a concurrent equivalent for System.Collections.Generic.HashSet<T>. At the moment, if a thread-safe hash set is needed, we are left with one of three options:

  • Creating a thread-safe collection class from scratch.
  • Synchronizing System.Collections.Generic.HashSet<T> in a wrapper class.
  • Using System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue> with "dummy" values such as object or byte, either directly or through a wrapper.

None of these approaches is ideal. The first and second option are both error prone (concurrency is hard) and difficult to fully optimize. The third wastes memory and time spent allocating the dummy objects. It seems reasonable to expect such a class wouldn't be too challenging to create given that it would appear to mostly consist of reducing the functionality in the already-existing ConcurrentDictionary<TKey, TValue> class (though that one is ~2,000 line long, so...).

Activity

  1. joshfree commented on Oct 1, 2015

    @joshfree
    Member
  2. daveaglick commented on Oct 1, 2015

    @daveaglick
    Author

    BTW - if this class is deemed appropriate, I certainly don't mind doing the initial legwork.

  3. daveaglick commented on Jul 14, 2016

    @daveaglick
    Author
  4. karelz commented on Sep 26, 2016

    @karelz
    Member

    Dupe of dotnet/corefx#6318

  5. transferred this issue fromdotnet/corefxon Jan 31, 2020
  6. added this to the 2.0.0 milestone on Jan 31, 2020
  7. ghost locked as resolved and limited conversation to collaborators on Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api-needs-workarea-System.Collections

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions