Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/runtime/time_go122.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func startTimer(tim *timer) {

//go:linkname stopTimer time.stopTimer
func stopTimer(tim *timer) bool {
// Set period to 0 to prevent the timer from being re-added to the queue
// if the callback is currently running. This must be done before removing
// the timer to avoid a race condition where the callback re-adds the timer
// after it's been removed.
tim.period = 0
return removeTimer(tim) != nil
}

Expand Down
5 changes: 5 additions & 0 deletions src/runtime/time_go123.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func newTimer(when, period int64, f func(arg any, seq uintptr, delta int64), arg

//go:linkname stopTimer time.stopTimer
func stopTimer(tim *timeTimer) bool {
// Set period to 0 to prevent the timer from being re-added to the queue
// if the callback is currently running. This must be done before removing
// the timer to avoid a race condition where the callback re-adds the timer
// after it's been removed.
tim.timer.period = 0
return removeTimer(&tim.timer) != nil
}

Expand Down
Loading