package main

import (
	"fmt"
	"sync"
)

type ScoreStore struct {
	mu     sync.Mutex
	scores map[string]int
}

func NewScoreStore() *ScoreStore {
	return &ScoreStore{scores: make(map[string]int)}
}

func (s *ScoreStore) Set(name string, score int) {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.scores[name] = score
}

func (s *ScoreStore) Get(name string) (int, bool) {
	s.mu.Lock()
	defer s.mu.Unlock()
	score, ok := s.scores[name]
	return score, ok
}

func main() {
	store := NewScoreStore()
	var wg sync.WaitGroup

	for name, score := range map[string]int{
		"ana": 91,
		"ben": 84,
		"cy":  88,
	} {
		name, score := name, score
		wg.Go(func() {
			store.Set(name, score)
		})
	}

	wg.Wait()
	score, ok := store.Get("ana")
	fmt.Println(score, ok)
}
