1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00

time: fix timer stop

Due to data structure corruption,
some timers could not be removed.
Fixes #2495.

R=golang-dev, adg
CC=golang-dev, mdbrown
https://golang.org/cl/5437060
This commit is contained in:
Dmitriy Vyukov 2011-11-25 14:13:10 +03:00
parent 38c082f69e
commit a899a467f2
2 changed files with 26 additions and 3 deletions

View File

@ -133,9 +133,16 @@ deltimer(Timer *t)
return false;
}
timers.t[i] = timers.t[--timers.len];
timers.len--;
if(i == timers.len) {
timers.t[i] = nil;
} else {
timers.t[i] = timers.t[timers.len];
timers.t[timers.len] = nil;
timers.t[i]->i = i;
siftup(i);
siftdown(i);
}
runtime·unlock(&timers);
return true;
}

View File

@ -205,3 +205,19 @@ func testAfterQueuing(t *testing.T) error {
}
return nil
}
func TestTimerStopStress(t *testing.T) {
if testing.Short() {
return
}
for i := 0; i < 100; i++ {
go func(i int) {
timer := AfterFunc(2e9, func() {
t.Fatalf("timer %d was not stopped", i)
})
Sleep(1e9)
timer.Stop()
}(i)
}
Sleep(3e9)
}