title: Go waitgroup with channel (worker)
body: <p>I'm trying to make simple worker pool in Go.
  After adding the wait group to the following program I'm facing deadlock.
  What is the core reason behind it?</p>
  <p>When I'm not using the wait group, program seems to be working fine.</p>
  <pre><code>fatal error: all goroutines are asleep - deadlock!
  
  goroutine 1 [semacquire]:
  sync.runtime_Semacquire(0xc0001b2ea8)
  
  </code></pre>
  <p>Program -</p>
  <pre><code>package main
  
  import (
      &quot;fmt&quot;
      &quot;strconv&quot;
      &quot;sync&quot;
  )
  
  func main() {
      workerSize := 2
      ProcessData(workerSize)
  }
  
  // ProcessData :
  func ProcessData(worker int) {
  
      // Create Jobs Pool for passong jobs to worker
      JobChan := make(chan string)
  
      //Produce the jobs
      var jobsArr []string
      for i := 1; i &lt;= 10000; i++ {
          jobsArr = append(jobsArr, &quot;Test &quot;+strconv.Itoa(i))
      }
  
      //Assign jobs to worker from jobs pool
      var wg sync.WaitGroup
      for w := 1; w &lt;= worker; w++ {
          wg.Add(1)
          // Consumer
          go func(jw int, wg1 *sync.WaitGroup) {
              defer wg1.Done()
              for job := range JobChan {
                  actualProcess(job, jw)
              }
          }(w, &amp;wg)
      }
  
      // Create jobs pool
      for _, job := range jobsArr {
          JobChan &lt;- job
      }
  
      wg.Wait()
      //close(JobChan)
  }
  
  func actualProcess(job string, worker int) {
      fmt.Println(&quot;WorkerID: #&quot;, worker, &quot;, Job Value: &quot;, job)
  }
  
  </code></pre>