package main

import (
	"fmt"
	"sync"
)

type Counter struct {
	mu    sync.Mutex
	value int
}

func (c *Counter) Increment() {
	c.mu.Lock()
	defer c.mu.Unlock()
	c.value++
}

func (c *Counter) Value() int {
	c.mu.Lock()
	defer c.mu.Unlock()
	return c.value
}

func main() {
	var counter Counter
	var workers sync.WaitGroup

	for range 3 {
		workers.Go(func() {
			for range 1_000 {
				counter.Increment()
			}
		})
	}

	workers.Wait()
	fmt.Println(counter.Value())
}
