diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-09-22 20:30:08 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-09-23 17:32:49 -0700 |
commit | 10a83805e047a583348e8bef18b966ecb8eee5d4 (patch) | |
tree | 0e35588beed26134397f6e25aa58dfd3600ed8db /libgo/go/sync | |
parent | 82b77dee751c916bcef55e527bffdd82b68fc897 (diff) | |
download | gcc-10a83805e047a583348e8bef18b966ecb8eee5d4.zip gcc-10a83805e047a583348e8bef18b966ecb8eee5d4.tar.gz gcc-10a83805e047a583348e8bef18b966ecb8eee5d4.tar.bz2 |
libgo: update to Go1.15.2 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/256618
Diffstat (limited to 'libgo/go/sync')
-rw-r--r-- | libgo/go/sync/map.go | 1 | ||||
-rw-r--r-- | libgo/go/sync/map_test.go | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/libgo/go/sync/map.go b/libgo/go/sync/map.go index a61e2eb..9ad2535 100644 --- a/libgo/go/sync/map.go +++ b/libgo/go/sync/map.go @@ -274,6 +274,7 @@ func (m *Map) LoadAndDelete(key interface{}) (value interface{}, loaded bool) { e, ok = read.m[key] if !ok && read.amended { e, ok = m.dirty[key] + delete(m.dirty, key) // Regardless of whether the entry was present, record a miss: this key // will take the slow path until the dirty map is promoted to the read // map. diff --git a/libgo/go/sync/map_test.go b/libgo/go/sync/map_test.go index 4ae989a..7f163ca 100644 --- a/libgo/go/sync/map_test.go +++ b/libgo/go/sync/map_test.go @@ -9,6 +9,7 @@ import ( "reflect" "runtime" "sync" + "sync/atomic" "testing" "testing/quick" ) @@ -171,3 +172,26 @@ func TestConcurrentRange(t *testing.T) { } } } + +func TestIssue40999(t *testing.T) { + var m sync.Map + + // Since the miss-counting in missLocked (via Delete) + // compares the miss count with len(m.dirty), + // add an initial entry to bias len(m.dirty) above the miss count. + m.Store(nil, struct{}{}) + + var finalized uint32 + + // Set finalizers that count for collected keys. A non-zero count + // indicates that keys have not been leaked. + for atomic.LoadUint32(&finalized) == 0 { + p := new(int) + runtime.SetFinalizer(p, func(*int) { + atomic.AddUint32(&finalized, 1) + }) + m.Store(p, struct{}{}) + m.Delete(p) + runtime.GC() + } +} |