Skip to content

Instantly share code, notes, and snippets.

@dagoof
dagoof / atomic.go
Created June 3, 2022 07:54
An atomic counter written in go ...
type Counter struct {
value int32
mutex sync.Mutex
}
func (c *Counter) Increment() {
defer c.mutex.Unlock()
c.mutex.Lock()
atomic.AddInt32(&c.value, 1)
}