我想,最简单的方法是创建 250 个 goroutine 并将它们传递给一个通道,您可以使用该通道将链接从主 goroutine 传递到子 goroutine,并监听该通道。当所有链接都传递给 goroutine 时,您关闭一个通道,所有 goroutine 就完成了它们的工作。为了在孩子处理数据之前完成主 goroutine 的安全,您可以使用sync.WaitGroup.下面是一些代码来说明我上面所说的(不是最终的工作版本,而是说明了这一点):func worker(linkChan chan string, wg *sync.WaitGroup) { // Decreasing internal counter for wait-group as soon as goroutine finishes defer wg.Done() for url := range linkChan { // Analyze value and do the job here }}func main() { lCh := make(chan string) wg := new(sync.WaitGroup) // Adding routines to workgroup and running then for i := 0; i < 250; i++ { wg.Add(1) go worker(lCh, wg) } // Processing all links by spreading them to `free` goroutines for _, link := range yourLinksSlice { lCh <- link } // Closing channel (waiting in goroutines won't continue any more) close(lCh) // Waiting for all goroutines to finish (otherwise they die as main routine dies) wg.Wait()}