syncmap
syncmap copied to clipboard
is it deadlock?
var b *SyncMap func init() { b = New() for i := 0; i < 10000000 ; i++ { b.Set(strconv.Itoa(i),i) } } // go test -v -run=TestIter func TestIter(t *testing.T) { i := <- b.IterItems() t.Log(i) b.Set(i.Key,0) }
all goroutines are asleep - deadlock!
should be iter func ?
The IterItems and IterKeys methods are designed to iterate over items or keys to get data from the map. It is not encouraged to modify during loop, this maybe leads to deadlock.
An example usage:
for item := range b.Iteritems() {
fmt.Println(item.Key, item.Value)
}
It's a good idea to add methods like ForEachKey and ForEachItem that accept a callback function to apply to each key or item. Pull requests are welcome.