Skip to content

Instantly share code, notes, and snippets.

@rlcarrca
Created February 10, 2026 16:43
Show Gist options
  • Select an option

  • Save rlcarrca/e29063a3338888dce84aa64d2a37a060 to your computer and use it in GitHub Desktop.

Select an option

Save rlcarrca/e29063a3338888dce84aa64d2a37a060 to your computer and use it in GitHub Desktop.
Mutex example snippet
type Counter struct {
mu sync.Mutex
value int
}
func (c *Counter) Increment() {
c.mu.Lock()
c.value++
c.mu.Unlock()
}
func (c *Counter) Value() int {
c.mu.Lock()
defer c.mu.Unlock()
return c.value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment