08_Channel Unbuffered

Send on unbuffered channel

  • When sender goroutine wants to send values. If there is corresponding receiver waiting in recvq. Sender will write the value directly into receiver goroutine stack variable. Sender goroutine puts the receiver goroutine back to runnables state.
  • If there no receiver goroutine in recvq. Sender gets parked into sendq. Data is saved in elem field in sudog struct. Receiver comes and copoes the data. Puts the sender to runnable state again.

Receive on unbuffered channel

  • Receiver goroutine wants to receive value. It it find a goroutine in waiting in sendq. Receiver copoes the value in elem field to its variable. Puts the sender goroutine to runnable state.
  • If there was no sender goroutine in sendq. Receiver gets parked into recvq. Reference to variable is saved in elem field in sudog struct. Sender comes and copoes the data directly to receiver stack variable. Puts the receiver to runnable state.
© Kimi Tsai all right reserved.            Updated : 2023-07-12 09:04:54

results matching ""

    No results matching ""

    results matching ""

      No results matching ""