import("fmt""runtime")/*结果:有时99有时100*/varcounter_numintconstMAXSIZE=100funcCount_num(chchanint){counter_num++ch
2 回答
撒科打诨
TA贡献1934条经验 获得超2个赞
packagemainimport("fmt""runtime""sync/atomic")/*结果:有时99有时100*/varcounter_numuint32=0constMAXSIZE=100funcCount_num(chchanuint32){atomic.AddUint32(&counter_num,1)ch<-counter_num}funcmain(){runtime.GOMAXPROCS(runtime.NumCPU())varchs[MAXSIZE]chanuint32fori:=0;ichs[i]=make(chanuint32) goCount_num(chs[i])}fori,ch:=rangechs{print("-----",i,"\n")print(<-ch,"\n")}fmt.Println(counter_num)}
添加回答
举报
0/150
提交
取消