aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/chan.go
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2025-06-02 09:26:27 -0700
committerGopher Robot <gobot@golang.org>2025-06-04 09:20:21 -0700
commit3432c68467d50ffc622fed230a37cd401d82d4bf (patch)
tree68e8152e4ba53aef6cb685d95ccc891b14d8c272 /src/runtime/chan.go
parent1aa336209363d9715e145244c7b22620ac0f0584 (diff)
downloadgo-3432c68467d50ffc622fed230a37cd401d82d4bf.tar.xz
runtime: make bubbled timers more consistent with unbubbled
This CL makes two changes to reduce the predictability with which bubbled timers fire. When asynctimerchan=0 (the default), regular timers with an associated channel are only added to a timer heap when some channel operation is blocked on that channel. This allows us to garbage collect unreferenced, unstopped timers. Timers in a synctest bubble, in contrast, are always added to the bubble's timer heap. This CL changes bubbled timers with a channel to be handled the same as unbubbled ones, adding them to the bubble's timer heap only when some channel operation is blocked on the timer's channel. This permits unstopped bubbled timers to be garbage collected, but more importantly it makes all timers past their deadline behave identically, regardless of whether they are in a bubble. This CL also changes timer scheduling to execute bubbled timers immediately when possible rather than adding them to a heap. Timers in a bubble's heap are executed when the bubble is idle. Executing timers immediately avoids creating a predictable order of execution. For #73850 Fixes #73934 Change-Id: If82e441546408f780f6af6fb7f6e416d3160295d Reviewed-on: https://go-review.googlesource.com/c/go/+/678075 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/chan.go')
-rw-r--r--src/runtime/chan.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/runtime/chan.go b/src/runtime/chan.go
index df48267e97..bb554ebfdb 100644
--- a/src/runtime/chan.go
+++ b/src/runtime/chan.go
@@ -497,7 +497,7 @@ func empty(c *hchan) bool {
// c.timer is also immutable (it is set after make(chan) but before any channel operations).
// All timer channels have dataqsiz > 0.
if c.timer != nil {
- c.timer.maybeRunChan()
+ c.timer.maybeRunChan(c)
}
return atomic.Loaduint(&c.qcount) == 0
}
@@ -542,7 +542,7 @@ func chanrecv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool)
}
if c.timer != nil {
- c.timer.maybeRunChan()
+ c.timer.maybeRunChan(c)
}
// Fast path: check for failed non-blocking operation without acquiring the lock.
@@ -821,7 +821,7 @@ func chanlen(c *hchan) int {
}
async := debug.asynctimerchan.Load() != 0
if c.timer != nil && async {
- c.timer.maybeRunChan()
+ c.timer.maybeRunChan(c)
}
if c.timer != nil && !async {
// timer channels have a buffered implementation