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

fix(xxhash3): fix data race #149

Merged
merged 1 commit into from
Aug 1, 2022

Conversation

HuangHongkai
Copy link
Contributor

xxhash单测出现开启-race出现报错,case

func TestConcurrent(t *testing.T) {
	var dataList = [][]byte{
		make([]byte, 1000),
		make([]byte, 1000),
		make([]byte, 1000),
	}
	var wg = sync.WaitGroup{}
	for _, data := range dataList {
		wg.Add(1)
		data := data
		go func() {
			// xxh3HashLarge
			Hash(data)
			wg.Done()
		}()
	}
	wg.Wait()
}

报错信息

=== RUN   TestConcurrent
==================
WARNING: DATA RACE
Write at 0x000001389480 by goroutine 21:
  github.com/bytedance/gopkg/util/xxhash3.xxh3HashLarge()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/hash.go:120 +0x2ef9
  github.com/bytedance/gopkg/util/xxhash3.Hash()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/hash.go:33 +0xc9
  github.com/bytedance/gopkg/util/xxhash3.TestConcurrent.func1()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/util_test.go:21 +0x4c

Previous write at 0x000001389480 by goroutine 20:
  github.com/bytedance/gopkg/util/xxhash3.xxh3HashLarge()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/hash.go:120 +0x2ef9
  github.com/bytedance/gopkg/util/xxhash3.Hash()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/hash.go:33 +0xc9
  github.com/bytedance/gopkg/util/xxhash3.TestConcurrent.func1()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/util_test.go:21 +0x4c

Goroutine 21 (running) created at:
  github.com/bytedance/gopkg/util/xxhash3.TestConcurrent()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/util_test.go:19 +0x23a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1193 +0x202

Goroutine 20 (finished) created at:
  github.com/bytedance/gopkg/util/xxhash3.TestConcurrent()
      /Users/huanghongkai/go/src/bytedance/gopkg/util/xxhash3/util_test.go:19 +0x23a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1193 +0x202
==================
    testing.go:1092: race detected during execution of test
--- FAIL: TestConcurrent (0.00s)
=== CONT  
    testing.go:1092: race detected during execution of test
FAIL
exit status 1
FAIL    github.com/bytedance/gopkg/util/xxhash3 12.903s

@zhangyunhao116 zhangyunhao116 self-requested a review July 29, 2022 11:00
@zhangyunhao116 zhangyunhao116 changed the title fix: fix xxhash3 data race fix(xxhash3): fix data race Aug 1, 2022
@zhangyunhao116 zhangyunhao116 merged commit 4820298 into bytedance:develop Aug 1, 2022
@zhangyunhao116
Copy link
Member

Thanks!

joway pushed a commit to joway/gopkg that referenced this pull request Apr 17, 2024
Co-authored-by: huanghongkai <huanghongkai@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants