Skip to content

Commit

Permalink
Fix Union thread safety
Browse files Browse the repository at this point in the history
Fixes `(*Set[V]).Union` to be thread safe properly.

Signed-off-by: micnncim <micnncim@gmail.com>
  • Loading branch information
micnncim committed Sep 10, 2022
1 parent b2ef3ae commit 20bcf70
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions set.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ func (s *Set[V]) Values() []V {
// s.Union(t) = {a1, a2, a3, a4}
// t.Union(s) = {a1, a2, a3, a4}
func (s *Set[V]) Union(t *Set[V]) *Set[V] {
u := s.Clone()

s.mux.RLock()
t.mux.RLock()
defer s.mux.RUnlock()
defer t.mux.RUnlock()

u := s.Clone()

for k := range t.m {
u.Insert(k)
}
Expand Down

0 comments on commit 20bcf70

Please sign in to comment.