From d5a5a13ad987db9bcdda8c6cecb84ed8583ea68d Mon Sep 17 00:00:00 2001 From: Changkun Ou Date: Mon, 26 Jul 2021 10:56:30 +0200 Subject: sync: clarify the validity to call Map methods inside Range This change clarifies that calling all Map methods inside the callback of Range is allowed. For further assurance, a nested range call test is also added. Fixes #46399 Change-Id: I0a766a5c1470e6b573ec35df1ccd62b2e46f1561 Reviewed-on: https://go-review.googlesource.com/c/go/+/337389 Reviewed-by: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Trust: Ian Lance Taylor --- src/sync/map.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/sync/map.go') diff --git a/src/sync/map.go b/src/sync/map.go index dfb62dd3e8..7a6c82e5c3 100644 --- a/src/sync/map.go +++ b/src/sync/map.go @@ -311,8 +311,9 @@ func (e *entry) delete() (value interface{}, ok bool) { // // Range does not necessarily correspond to any consistent snapshot of the Map's // contents: no key will be visited more than once, but if the value for any key -// is stored or deleted concurrently, Range may reflect any mapping for that key -// from any point during the Range call. +// is stored or deleted concurrently (including by f), Range may reflect any +// mapping for that key from any point during the Range call. Range does not +// block other methods on the receiver; even f itself may call any method on m. // // Range may be O(N) with the number of elements in the map even if f returns // false after a constant number of calls. -- cgit v1.3-5-g9baa