Timer callbacks occasionally crash
with "sched while holding locks" message.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/
5381043
{
int64 delta, now;
Timer *t;
+ void (*f)(int64, Eface);
+ Eface arg;
for(;;) {
runtime·lock(&timers);
siftdown(0);
t->i = -1; // mark as removed
}
- t->f(now, t->arg);
+ f = t->f;
+ arg = t->arg;
+ runtime·unlock(&timers);
+ f(now, arg);
+ runtime·lock(&timers);
}
if(delta < 0) {
// No timers left - put goroutine to sleep.
import (
"errors"
"fmt"
+ "runtime"
"sort"
+ "sync/atomic"
"testing"
. "time"
)
<-c
}
+func TestAfterStress(t *testing.T) {
+ stop := uint32(0)
+ go func() {
+ for atomic.LoadUint32(&stop) == 0 {
+ runtime.GC()
+ }
+ }()
+ c := Tick(1)
+ for i := 0; i < 100; i++ {
+ <-c
+ }
+ atomic.StoreUint32(&stop, 1)
+}
+
func BenchmarkAfterFunc(b *testing.B) {
i := b.N
c := make(chan bool)