We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug When multiple coroutines call GetOrInsert at the same time, data may be missed during Range query.
GetOrInsert
To Reproduce
func main() { m := hashmap.New[string, bool]() wg := sync.WaitGroup{} for i := 0; i < 1000; i++ { wg.Add(1) kk := strconv.Itoa(i) go func() { m.GetOrInsert(kk, true) wg.Done() }() } wg.Wait() tmp := make([]string, 0) m.Range(func(key string, value bool) bool { tmp = append(tmp, key) return true }) log.Println(len(tmp), "/", m.Len()) // print: 9XX / 1000 }
Expected behavior Return data correctly
System (please complete the following information):
Additional context When called repeatedly, Len() may be larger than the actual length.
Len()
func main() { m := hashmap.New[string, bool]() wg := sync.WaitGroup{} for i := 0; i < 1000; i++ { wg.Add(1) kk := strconv.Itoa(i) go func() { m.GetOrInsert(kk, true) // call m.GetOrInsert(kk, true) // repeat call m.GetOrInsert(kk, true) // repeat call m.GetOrInsert(kk, true) // repeat call wg.Done() }() } wg.Wait() tmp := make([]string, 0) m.Range(func(key string, value bool) bool { tmp = append(tmp, key) return true }) log.Println(m.Len()) // m.Len() may be > 1000 }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
When multiple coroutines call
GetOrInsert
at the same time, data may be missed during Range query.To Reproduce
Expected behavior
Return data correctly
System (please complete the following information):
Additional context
When called repeatedly,
Len()
may be larger than the actual length.The text was updated successfully, but these errors were encountered: