Skip to content

Instantly share code, notes, and snippets.

@dannypsnl
Last active February 13, 2018 03:13
Show Gist options
  • Save dannypsnl/c5d7bd68ba4720a3e08f4bf7aa8c3e82 to your computer and use it in GitHub Desktop.
Save dannypsnl/c5d7bd68ba4720a3e08f4bf7aa8c3e82 to your computer and use it in GitHub Desktop.
package singleton
import (
"sync"
)
type singleton struct {
mu sync.Mutex
counter int
}
func (s *singleton) Addone() {
s.mu.Lock()
s.counter++
s.mu.Unlock()
}
var s *singleton
func init() {
s = &singleton{
counter: 0,
}
}
func GetInstance() *singleton {
return s
}
@dannypsnl
Copy link
Author

Write Lock
Read Free

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment