[go] sync: document guidance on Cond.Broadcast regarding holding the lock

0 views
Skip to first unread message

Joseph Tsai (Gerrit)

unread,
Apr 24, 2026, 5:14:11 PM (16 hours ago) Apr 24
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Rondale Sidbury, Michael Pratt, Mark Freeman, golang...@luci-project-accounts.iam.gserviceaccount.com, Ian Lance Taylor, Austin Clements, golang-co...@googlegroups.com

Joseph Tsai submitted the change

Change information

Commit message:
sync: document guidance on Cond.Broadcast regarding holding the lock

As currently written, the documentation provides no guidance
on whether the lock should be held and seems to imply
that it does not really matter.

However, it does matter. In a heavily loaded production system,
there might be a million goroutines waiting on the condition,
calling Broadcast while holding the lock can cost ~100ms
of synchronous time notifying each of the waiters
(none of which can run anyways since the lock is still held).

At least surface the O(N) cost of Broadcast more clearly.
Change-Id: Ib1c7896826b0753cb79f3a62a3bace7612e58dcf
Reviewed-by: Mark Freeman <markf...@google.com>
Reviewed-by: Michael Pratt <mpr...@google.com>
Reviewed-by: Ian Lance Taylor <ia...@golang.org>
Reviewed-by: Rondale Sidbury <rondale...@gmail.com>
Files:
  • M src/sync/cond.go
Change size: XS
Delta: 1 file changed, 4 insertions(+), 2 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ib1c7896826b0753cb79f3a62a3bace7612e58dcf
Gerrit-Change-Number: 752480
Gerrit-PatchSet: 3
Gerrit-Owner: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Joseph Tsai <joe...@digital-static.net>
Gerrit-Reviewer: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
Gerrit-Reviewer: Rondale Sidbury <rondale...@gmail.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages