• 有没有 Java 背景问题不大的。

  • 我的答案是:

    package main
    
    import (
        "fmt"
        "math/rand"
        "sync"
        "sync/atomic"
    )
    
    func main() {
        dones := [100][10]chan int{}
    
        var wg sync.WaitGroup
        var count int32
        wg.Add(10)
        for i := 0; i < 10; i++ {
            go func() {
                c := atomic.AddInt32(&count, 1)
                a := rand.Intn(100)
                dones[a][c-1] = make(chan int)
                wg.Done()
                <-dones[a][c-1]
                fmt.Println(a)
                <-dones[a][c-1]
            }()
        }
        wg.Wait()
        for i := 0; i < 100; i++ {
            for j := 0; j < 10; j++ {
                if dones[i][j] != nil {
                    dones[i][j] <- 0
                    dones[i][j] <- 0
                }
            }
        }
    
    }