0
go DelegateWork(mr, <-mr.impl.readyWorkers, jobArgs)    

In the above example, would the channel receive operator cause the caller or the called goroutine to block?

2
  • 1
    Yes, of course. How could it not block? What would the semantics be if this would be somehow non-blocking? Why should that not be blocking?
    – Volker
    Jan 29, 2021 at 16:30
  • 1
    Well, you're passing values, aren't you, so obviously you're going to have to wait until a value was read from the channel prior to actually calling the function/starting the new routine. Jan 29, 2021 at 17:01

1 Answer 1

7

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.

So if <-mr.impl.readyWorkers blocks, it blocks the caller goroutine, before the new goroutine is launched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.