并发安全的有锁map

并发安全的有锁map 【并发安全的有锁map】直接上代码吧:

type LockMap struct { sync.RWMutex Map map[string]bool}func (d *LockMap) Get(key string) bool { d.RLock() value := d.Map[key] d.RUnlock() return value }func (d *LockMap) Set(key string, value bool) { d.Lock() d.Map[key] = value d.Unlock() }

    推荐阅读