We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetInfos() 函数返回前并没有等待 info_ch 里面的数据处理完:
GetInfos()
info_ch
go func(info_ch chan *Info, list *[]Info) { for { tmp := <-info_ch if tmp != nil { *list = append(*list, *tmp) } } }(info_ch, &list)
我运行了该程序几次,大部分时候的结果都是漏加了数据。把上面的代码 sleep 一下,就 100% 重现了:
go func(info_ch chan *Info, list *[]Info) { for { tmp := <-info_ch time.Sleep(time.Millisecond * 10) if tmp != nil { *list = append(*list, *tmp) } } }(info_ch, &list)
正确的做法要保证这个 goroutine 处理完数据该函数才返回。
The text was updated successfully, but these errors were encountered:
3567135
谢谢。这个重现率不是很高,以至于一直都没有发现……
Sorry, something went wrong.
No branches or pull requests
GetInfos()
函数返回前并没有等待info_ch
里面的数据处理完:我运行了该程序几次,大部分时候的结果都是漏加了数据。把上面的代码 sleep 一下,就 100% 重现了:
正确的做法要保证这个 goroutine 处理完数据该函数才返回。
The text was updated successfully, but these errors were encountered: