Last active
February 13, 2018 03:13
-
-
Save dannypsnl/c5d7bd68ba4720a3e08f4bf7aa8c3e82 to your computer and use it in GitHub Desktop.
This file contains 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write Lock
Read Free