aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/runtime/sema_test.go
diff options
context:
space:
mode:
authorGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-22 17:43:43 -0300
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-22 17:43:43 -0300
commita926878ddbd5a98b272c22171ce58663fc04c3e0 (patch)
tree86af256e5d9a9c06263c00adc90e5fe348008c43 /libgo/go/runtime/sema_test.go
parent542730f087133690b47e036dfd43eb0db8a650ce (diff)
parent07cbaed8ba7d1b6e4ab3a9f44175502a4e1ecdb1 (diff)
downloadgcc-devel/autopar_devel.zip
gcc-devel/autopar_devel.tar.gz
gcc-devel/autopar_devel.tar.bz2
Merge branch 'autopar_rebase2' into autopar_develdevel/autopar_devel
Quickly commit changes in the rebase branch.
Diffstat (limited to 'libgo/go/runtime/sema_test.go')
-rw-r--r--libgo/go/runtime/sema_test.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/libgo/go/runtime/sema_test.go b/libgo/go/runtime/sema_test.go
index 8bd5d4c..cf3de0a 100644
--- a/libgo/go/runtime/sema_test.go
+++ b/libgo/go/runtime/sema_test.go
@@ -6,6 +6,7 @@ package runtime_test
import (
. "runtime"
+ "sync"
"sync/atomic"
"testing"
)
@@ -61,8 +62,11 @@ func testSemaHandoff() bool {
// to another goroutine. Stop the current goroutine from migrating to
// another CPU where it can win the race (and appear to have not yielded) by
// keeping the CPUs slightly busy.
+ var wg sync.WaitGroup
for i := 0; i < GOMAXPROCS(-1); i++ {
+ wg.Add(1)
go func() {
+ defer wg.Done()
for {
select {
case <-done:
@@ -74,7 +78,9 @@ func testSemaHandoff() bool {
}()
}
+ wg.Add(1)
go func() {
+ defer wg.Done()
Semacquire(&sema)
atomic.CompareAndSwapUint32(&res, 0, 1)
@@ -91,7 +97,7 @@ func testSemaHandoff() bool {
Semrelease1(&sema, true, 0)
atomic.CompareAndSwapUint32(&res, 0, 2)
- <-done // wait for goroutines to finish to avoid data races
+ wg.Wait() // wait for goroutines to finish to avoid data races
return res == 1 // did the waiter run first?
}