diff --git a/safety/safemap.go b/safety/safemap.go index cab85ab..06a54bf 100644 --- a/safety/safemap.go +++ b/safety/safemap.go @@ -320,7 +320,9 @@ func (e *entry[V]) delete(px unsafe.Pointer) (value V, ok bool) { func (m *Map[K, V]) Flush() { m.mu.Lock() - m.missLocked() + m.dirty = nil + m.read.Store(readOnly[K, V]{m: m.dirty}) + m.misses = 0 m.mu.Unlock() } diff --git a/safety/safemap_test.go b/safety/safemap_test.go index aea66bc..6591018 100644 --- a/safety/safemap_test.go +++ b/safety/safemap_test.go @@ -32,10 +32,12 @@ func TestMap_Load(t *testing.T) { } p := taskPools.NewPools(10) var a0, a1 []int - for i := 0; i < 5000; i++ { - v := number.Rand(0, 1) + for i := 0; i < 15000; i++ { + v := number.Rand(0, 2) if 1 == v { a1 = append(a1, 1) + } else if 0 == v { + m.Flush() } else { a0 = append(a0, 0) }