mirror of
https://github.com/golang/go
synced 2024-11-21 16:14:42 -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:
parent
38c082f69e
commit
a899a467f2
@ -133,9 +133,16 @@ deltimer(Timer *t)
|
||||
return false;
|
||||
}
|
||||
|
||||
timers.t[i] = timers.t[--timers.len];
|
||||
siftup(i);
|
||||
siftdown(i);
|
||||
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;
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user