Commit a899a467 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent 38c082f6
...@@ -133,9 +133,16 @@ deltimer(Timer *t) ...@@ -133,9 +133,16 @@ deltimer(Timer *t)
return false; 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); siftup(i);
siftdown(i); siftdown(i);
}
runtime·unlock(&timers); runtime·unlock(&timers);
return true; return true;
} }
......
...@@ -205,3 +205,19 @@ func testAfterQueuing(t *testing.T) error { ...@@ -205,3 +205,19 @@ func testAfterQueuing(t *testing.T) error {
} }
return nil 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)
}
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