2,190
社区成员
发帖
与我相关
我的任务
分享
var (
fivePersonList [][]*player = make([][]*player, 0, 64)
fivePersonMutex sync.Mutex
)
func produce(){
//创建matchPlayerList
matchPlayerList :=make([]*player,0, 5)
//向matchplayerList追加数据,省略....
fivePersonMutex.Lock()
fivePersonMutex.Unlock()
fivePersonList = append(fivePersonList, matchPlayerList)\
}
func fetch() {
fivePersonMutex.Lock()
defer fivePersonMutex.Unlock()
if len(fivePersonList) == 0 {
return nil, false
}
//组装
retList := make([]*player, 0, 5)
//从中提取一个
retList = append(retList, fivePersonList[0]...)
//append这个地方,总数会报错,panic: runtime error:
// invalid memory address or nil
// pointer dereference
fivePersonList = fivePersonList[1:]
//.....
}
func main() {
go produce()
go fetch()
}