mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
Synchronize
This commit is contained in:
27
maps/concurrence_test.go
Normal file
27
maps/concurrence_test.go
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user