for i := 0; i < len(rf.peers); i++ {
DPrintf("i = %d", i)
if i == rf.me {
DPrintf("skipping myself #%d", rf.me)
continue
}
go func() {
DPrintf("len of rf.peers = %d", len(rf.peers))
DPrintf("server #%d sending request vote to server %d", rf.me, i)
reply := &RequestVoteReply{}
ok := rf.sendRequestVote(i, args, reply)
if ok && reply.VoteGranted && reply.Term == rf.currentTerm {
rf.voteCount++
if rf.voteCount > len(rf.peers)/2 {
rf.winElectionCh <- true
}
}
}()
} for val := range values {
go val.MyMethod()
} for val := range values {
go func() {
fmt.Println(val)
}()
} for val := range values {
go func(val interface{}) {
fmt.Println(val)
}(val)
} for i := range valslice {
val := valslice[i]
go func() {
fmt.Println(val)
}()
} server := i
总结
以上就是实例详解关于Golang中for-loop与goroutine的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于实例详解关于Golang中for-loop与goroutine的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did84497