gotdd/sync.go
2022-01-19 23:20:12 -05:00

23 lines
258 B
Go

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{}
}