You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (dict *ConcurrentDict) RWLocks(writeKeys []string, readKeys []string) {
keys := append(writeKeys, readKeys...)
// Lock in normal order
indices := dict.toLockIndices(keys, false)
writeIndexSet := make(map[uint32]struct{})
for _, wKey := range writeKeys {
idx := dict.spread(fnv32(wKey))
writeIndexSet[idx] = struct{}{}
}
for _, index := range indices {
_, w := writeIndexSet[index]
mu := &dict.table[index].mutex
if w {
mu.Lock()
} else {
mu.RLock()
}
}
}
// RWUnLocks unlocks write keys and read keys together. allow duplicate keys
func (dict *ConcurrentDict) RWUnLocks(writeKeys []string, readKeys []string) {
keys := append(writeKeys, readKeys...)
// Unlock in reverse order
indices := dict.toLockIndices(keys, true)
writeIndexSet := make(map[uint32]struct{})
for _, wKey := range writeKeys {
idx := dict.spread(fnv32(wKey))
writeIndexSet[idx] = struct{}{}
}
for _, index := range indices {
_, w := writeIndexSet[index]
mu := &dict.table[index].mutex
if w {
mu.Unlock()
} else {
mu.RUnlock()
}
}
}
why release lock reverse order in RWUnLocks?
Or If release lock in normal or random order,can cause some race problem?
Thanks
The text was updated successfully, but these errors were encountered:
That , Thread 1 locks in the order of A-B,and thread 2 locks in the order of B-A, will cause a deadlock.Therefore, the same order must be used for locking. The reverse order of unlocking and locking is just in case.
why release lock reverse order in RWUnLocks?
Or If release lock in normal or random order,can cause some race problem?
Thanks
The text was updated successfully, but these errors were encountered: