下列代码的输出结果为(    &n...
发布于 2022-03-03 11:34:18
下列代码的输出结果为( )
package main
import (
"sync"
)
const N = 10
func main() {
m := make(map[int]int)
syncwg := &sync.WaitGroup{}
syncmu := &sync.Mutex{}
syncwg.Add(N)
for i := 0 i < N i++ {
go func() {
defer syncwg.Done()
syncmu.Lock()
m[i] = i
syncmu.Unlock()
}()
}
syncwg.Wait()
println(len(m))
}
package main
import (
"sync"
)
const N = 10
func main() {
m := make(map[int]int)
syncwg := &sync.WaitGroup{}
syncmu := &sync.Mutex{}
syncwg.Add(N)
for i := 0 i < N i++ {
go func() {
defer syncwg.Done()
syncmu.Lock()
m[i] = i
syncmu.Unlock()
}()
}
syncwg.Wait()
println(len(m))
}
登录后免费查看答案
关注者
0
被浏览
8