Answer the question
In order to leave comments, you need to log in
Thread safety and pointers. Need blocking?
Googled.
Let's say there is some code that returns a pointer
func Db(name string) *DB{
rw.RLock()
_, ok := database[name]
rw.RUnlock()
if !ok {
newDb(name)
Db(name)
}
return database[name]
}
func (d *DB) Set(key string, value interface{}) bool {
log.Println("cache.Set: ",key, " Value: ", value)
d.RW.Lock()
defer d.RW.Unlock()
_, ok := d.Storage[key]
if ok {
log.Println("cache.Set: ",key, " exist")
return false
}
d.Storage[key] = value
return true
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question