From 258434c5f3d76d6505dde134f17a0ba390fae0a6 Mon Sep 17 00:00:00 2001 From: jizhuozhi Date: Mon, 22 Jul 2024 01:49:10 +0800 Subject: [PATCH] test: with data race --- .github/workflows/go.yml | 2 +- future.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index a189a30..e1e6c6f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -22,7 +22,7 @@ jobs: go-version: '1.18' - name: Test - run: go test -v ./... -coverprofile=coverage.out -covermode=atomic + run: go test -race -coverprofile=coverage.out -covermode=atomic -v ./... - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4.0.1 diff --git a/future.go b/future.go index 4fcd3c3..33845ff 100644 --- a/future.go +++ b/future.go @@ -95,6 +95,9 @@ func (s *state[T]) get() (T, error) { } if atomic.CompareAndSwapUint64(&s.state, st, st+1) { runtime_Semacquire(&s.sema) + if (atomic.LoadUint64(&s.state)&maskState)>>32 != stateDone { + panic("sync: notified before state has done") + } return s.val, s.err } }