go channel basics

tags: learning go programming

content

  • channels are typed, thread-safe
  • channels are queues
  • channels allow different threads to talk to each other
  • channels have buffer, it’s like the queue’s length
    • if a channel’s buffer is 0, that means the queue’s length is 0
    • the queue has to be read once there’s data sent to it, otherwise the sender will get blocked

creating a channel for sending integer data: ch := make(chan int) sending data into the channel: ch <- 69 receiving data from the channel: v := <- ch

up

go-routine-basics go-deadlock

down

thread-safety

reference