Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
daveaglick opened this issue Sep 30, 2015 · 5 comments
Closed

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

daveaglick opened this issue Sep 30, 2015 · 5 comments
Assignees
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Collections
Milestone

Comments

@daveaglick
Copy link

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...).

@joshfree
Copy link
Member

joshfree commented Oct 1, 2015

/cc @terrajobst

@daveaglick
Copy link
Author

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

@redknightlois
Copy link

I just had to use this (http://pastebin.com/8REHRFFL) minutes ago. @daveaglick beat me to report it. :P

@daveaglick
Copy link
Author

FYI, for anyone stumbling on this issue - @i3arnon has an implementation here: https://github.com/i3arnon/ConcurrentHashSet (https://www.nuget.org/packages/ConcurrentHashSet/)

@karelz
Copy link
Member

karelz commented Sep 26, 2016

Dupe of dotnet/corefx#6318

@karelz karelz closed this as completed Sep 26, 2016
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Collections
Projects
None yet
Development

No branches or pull requests

6 participants