Commit dada467f authored by Russ Cox's avatar Russ Cox

cmd/go/internal/par: actually make par.Work run things in parallel

This was an unfortunate debugging print introduced
while working on the unfortunately large CL 123576.
At least now we're done with that awfulness.

Change-Id: Ib83db59382a799f649832d22d3c6f039d2ef9d2c
Reviewed-on: https://go-review.googlesource.com/125015Reviewed-by: 's avatarBryan C. Mills <bcmills@google.com>
parent ef459457
......@@ -55,7 +55,6 @@ func (w *Work) Do(n int, f func(item interface{})) {
if n < 1 {
panic("par.Work.Do: n < 1")
}
n = 1
if w.running >= 1 {
panic("par.Work.Do: already called Do")
}
......
......@@ -7,6 +7,7 @@ package par
import (
"sync/atomic"
"testing"
"time"
)
func TestWork(t *testing.T) {
......@@ -30,6 +31,30 @@ func TestWork(t *testing.T) {
}
}
func TestWorkParallel(t *testing.T) {
var w Work
for tries := 0; tries < 10; tries++ {
const N = 100
for i := 0; i < N; i++ {
w.Add(i)
}
start := time.Now()
var n int32
w.Do(N, func(x interface{}) {
time.Sleep(1 * time.Millisecond)
atomic.AddInt32(&n, +1)
})
if n != N {
t.Fatalf("par.Work.Do did not do all the work")
}
if time.Since(start) < N/2*time.Millisecond {
return
}
}
t.Fatalf("par.Work.Do does not seem to be parallel")
}
func TestCache(t *testing.T) {
var cache Cache
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment