title: Golang: Why does increasing the size of a buffered channel eliminate output from my goroutines?
body: <p>I am trying to understand why making the buffer size of a channel larger changes causes my code to run unexpectedly. If the buffer is smaller than my input (100 ints), the output is as expected, i.e., 7 goroutines each read a subset of the input and send output on another channel which prints it. If the buffer is the same size or larger than the input, I get no output and no error. Am I closing a channel at the wrong time? Do I have the wrong expectation about how buffers work? Or, something else?</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "sync"
  )
  
  var wg1, wg2 sync.WaitGroup
  
  func main() {
      share := make(chan int, 10)
      out := make(chan string)
      go printChan(out)
      for j:= 1; j&lt;=7; j++ {
          go readInt(share, out, j)
      }
      for i:=1; i&lt;=100; i++ {
          share &lt;- i
      }
      close(share)
      wg1.Wait()
      close(out)
      wg2.Wait()
  }
  func readInt(in chan int, out chan string, id int) {
      wg1.Add(1)
      for n := range in {
          out &lt;- fmt.Sprintf("goroutine:%d was sent %d", id, n)
      }
      wg1.Done()
  }
  func printChan(out chan string){
      wg2.Add(1)
      for l := range out {
          fmt.Println(l)
      }
      wg2.Done()
  }
  </code></pre>
  
  <p>To run this:
  Small buffer, expected output. <a href="http://play.golang.org/p/4r7rTGypPO" rel="nofollow">http://play.golang.org/p/4r7rTGypPO</a>
  Big buffer, no output. <a href="http://play.golang.org/p/S-BDsw7Ctu" rel="nofollow">http://play.golang.org/p/S-BDsw7Ctu</a></p>