I’m wondering if there exists somewhere a data structure that could track a set of thread ids? Obviously, one could use a
Mutex<HashSet<ThreadId>>, but that would make every addition or removal of a thread take the lock. Since in my scenario (which seems like it must be common) each thread would only add and remove itself, so I could imagine using lock-free thread-local storage to make this fast. I also will need to be able to (possibly slowly) identify whether the set is empty from a single thread.
Any ideas whether this sort of structure exists in one of the many threading libraries? Or something that could be used to implement this? Or how I might create such a data structure?