package main

import (
	"fmt"
	"sync"
)

type Store struct {
	mu   sync.RWMutex
	data map[string]int
}

func NewStore() *Store {
	return &Store{data: make(map[string]int)}
}

func (s *Store) Set(key string, value int) {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.data[key] = value
}

func (s *Store) Get(key string) (int, bool) {
	s.mu.RLock()
	defer s.mu.RUnlock()
	value, ok := s.data[key]
	return value, ok
}

func main() {
	store := NewStore()
	var writers sync.WaitGroup

	writers.Go(func() { store.Set("one", 1) })
	writers.Go(func() { store.Set("two", 2) })
	writers.Go(func() { store.Set("three", 3) })
	writers.Wait()

	for _, key := range []string{"one", "two", "three"} {
		value, _ := store.Get(key)
		fmt.Printf("%s = %d\n", key, value)
	}
}
