1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00

Synchronize

This commit is contained in:
2022-05-12 14:32:58 +08:00
parent 8e33d9dd92
commit c7864d5dc8
3 changed files with 73 additions and 8 deletions

27
maps/concurrence_test.go Normal file
View File

@ -0,0 +1,27 @@
package maps
import (
"sync"
"testing"
"time"
)
func TestConcurrence(t *testing.T) {
m := NewHashMap(map[string]any{"a": "a"}).Synchronize()
var wg = &sync.WaitGroup{}
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()
m.Set("b", "b")
m.Get("a")
time.Sleep(time.Second)
}()
}
wg.Wait()
}