gotdd/sync.go

23 lines
258 B
Go
Raw Permalink Normal View History

2022-01-20 04:20:12 +00:00
package main
import "sync"
type Counter struct {
mu sync.Mutex
value int
}
func (c *Counter) Inc() {
c.mu.Lock()
defer c.mu.Unlock()
c.value++
}
func (c *Counter) Value() int {
return c.value
}
func NewCounter() *Counter {
return &Counter{}
}