Created
June 23, 2017 21:27
-
-
Save shelomentsevd/00388cb9e19a4bad0a61fed784f2b3cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Store struct { | |
mutex sync.RWMutex | |
data map[string]int | |
} | |
func (s * Store) Read(key string) int, error { | |
// ... | |
defer s.mutex.RUnlock() | |
s.mutex.RLock() | |
// ... | |
return val, nil | |
} | |
func (s * Store) Write(key string, value int) error { | |
// ... | |
defer s.mutex.Unlock() | |
s.mutex.Lock() | |
// ... | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment