
1

goroutine 传指针的问题
source link: https://www.v2ex.com/t/807900
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

goroutine 传指针的问题
for {
select {
case msg, ok := <-msgChan:
if !ok {
return
}
limit <- struct{}{}
go func(t *Message) {
send(t)
<-limit
}(msg)
}
}
msg 是*Message
这样的传参会导致 t 被下次循环的 msg 覆盖吗 (其实可以不这么控制并发,如果只能这么写的话
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK