1
0
mirror of https://github.com/golang/go synced 2024-11-13 18:50:24 -07:00

runtime: fix TestLFStackStress

Fixes #7138.

R=r, bradfitz, dave
CC=dvyukov, golang-codereviews
https://golang.org/cl/53910043
This commit is contained in:
Russ Cox 2014-01-17 17:42:24 -05:00
parent 5c9585953f
commit 98178b345a

View File

@ -71,6 +71,8 @@ func TestLFStack(t *testing.T) {
} }
} }
var stress []*MyNode
func TestLFStackStress(t *testing.T) { func TestLFStackStress(t *testing.T) {
const K = 100 const K = 100
P := 4 * GOMAXPROCS(-1) P := 4 * GOMAXPROCS(-1)
@ -80,14 +82,15 @@ func TestLFStackStress(t *testing.T) {
} }
// Create 2 stacks. // Create 2 stacks.
stacks := [2]*uint64{new(uint64), new(uint64)} stacks := [2]*uint64{new(uint64), new(uint64)}
// Need to keep additional referenfces to nodes, the stack is not all that type-safe. // Need to keep additional references to nodes,
var nodes []*MyNode // the lock-free stack is not type-safe.
stress = nil
// Push K elements randomly onto the stacks. // Push K elements randomly onto the stacks.
sum := 0 sum := 0
for i := 0; i < K; i++ { for i := 0; i < K; i++ {
sum += i sum += i
node := &MyNode{data: i} node := &MyNode{data: i}
nodes = append(nodes, node) stress = append(stress, node)
LFStackPush(stacks[i%2], fromMyNode(node)) LFStackPush(stacks[i%2], fromMyNode(node))
} }
c := make(chan bool, P) c := make(chan bool, P)
@ -127,4 +130,7 @@ func TestLFStackStress(t *testing.T) {
if sum2 != sum { if sum2 != sum {
t.Fatalf("Wrong sum %d/%d", sum2, sum) t.Fatalf("Wrong sum %d/%d", sum2, sum)
} }
// Let nodes be collected now.
stress = nil
} }