Skip to content

Instantly share code, notes, and snippets.

@shelomentsevd
Created June 23, 2017 21:27
Show Gist options
  • Save shelomentsevd/00388cb9e19a4bad0a61fed784f2b3cb to your computer and use it in GitHub Desktop.
Save shelomentsevd/00388cb9e19a4bad0a61fed784f2b3cb to your computer and use it in GitHub Desktop.
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