mutex in a struct
tags: learning go programming
content
- it’s common to see this pattern, where mutex is included in a struct with some other data:
type Container struct{
value int
mutex sync.Mutex
}- and later be used like:
func (c *Container) someFunc() {
c.mutex.Lock()
defer c.mutex.Unlock()
// do something with c.value
}