Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- type SafeCounter struct {
- v map[string]int
- }
- func (c *SafeCounter) Inc(key string) {
- c.v[key]++
- }
- func (c *SafeCounter) Value(key string) int {
- return c.v[key]
- }
- func main() {
- c := SafeCounter{v: make(map[string]int)}
- for i := 0; i < 1000; i++ {
- go c.Inc("somekey")
- }
- fmt.Println(c.Value("somekey"))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement