【发布时间】:2023-04-08 02:24:01
【问题描述】:
scores := make(map[string]int)
percentage := make(map[string]float64)
total := 0
for i, ans := range answers {
answers[i] = strings.ToLower(ans)
}
wg := sync.WaitGroup{}
go func() {
wg.Add(1)
body, _ := google(question)
for _, ans := range answers {
count := strings.Count(body, ans)
total += count
scores[ans] += 5 // <------------------- This doesn't work
}
wg.Done()
}()
这是一段 sn-p 代码,我的问题是,我无法修改分数,我尝试过使用指针,我尝试过正常操作,我尝试过将其作为参数传递。
【问题讨论】:
标签: multithreading pointers go maps goroutine