Skip to content

这一章节有错误: 1.5.6 基于Channel的通信  #550

@givetimetolife

Description

@givetimetolife

我们可以根据控制Channel的缓存大小来控制并发执行的Goroutine的最大数目, 例如:

var limit = make(chan int, 3)

func main() {
    for _, w := range work {
        go func() {
            limit <- 1
            w()
            <-limit
        }()
    }
    select{}
}

应该把limit <- 1 放在 go fun() 之前,才能控制并发Goroutine的最大数目,

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions