gpt4 book ai didi

go - goroutine调用中 channel 接收运算符的阻塞行为

转载 作者:行者123 更新时间:2023-12-03 10:09:45 25 4
gpt4 key购买 nike

go DelegateWork(mr, <-mr.impl.readyWorkers, jobArgs)    
在上面的示例中, channel 接收运算符会导致调用方或被调用的goroutine阻塞吗?

最佳答案

Spec: Go statements:

The function value and parameters are evaluated as usual in the calling goroutine, but unlike with a regular call, program execution does not wait for the invoked function to complete. Instead, the function begins executing independently in a new goroutine.


因此,如果 <-mr.impl.readyWorkers阻止,它将在启动新的goroutine之前阻止调用方goroutine。

关于go - goroutine调用中 channel 接收运算符的阻塞行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65957823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com