title: How can i detect a deadlock?
body: <p>I just recently started learning go and wanted to test my skills by writing a program that calculates all amicable and perfect numbers. Sadly I'm having issues with my code! If anyone knows how I can stop the program after all numbers are calculated, preferably without an error, please let me know.</p>
  
  <pre class="lang-golang prettyprint-override"><code>package main
  
  import (
      "fmt"
      "strings"
  )
  
  func getDivisorSum(number int) int {
      divisors := 0
  
      for possibleDivisor := 1; possibleDivisor &lt;= number / 2; possibleDivisor++ {
          if number % possibleDivisor == 0 {
              divisors += possibleDivisor
          }
      }
  
      return divisors
  }
  
  func checkNumber(number int, channel chan string, done *int) {
      first := getDivisorSum(number)
  
      if first == number {
          channel &lt;- fmt.Sprintf("%d", number)
          *done += 1
          return
      }
  
      second := getDivisorSum(first)
  
      if number == second {
          channel &lt;- fmt.Sprintf("%d:%d", number, first)
          *done += 1
          return
      }
  }
  
  func checkNumberRange(min int, max int) {
      channel := make(chan string)
      done := 0
  
      for number := min; number &lt;= max; number++ {
          go checkNumber(number, channel, &amp;done)
      }
  
      for {
          tmp := &lt;- channel
  
          if strings.Contains(tmp, ":") {
              parts := strings.Split(tmp, ":")
              fmt.Printf("%s is an amicable of %s!\n", parts[0], parts[1])
          } else {
              fmt.Printf("%s is perfect!\n", tmp)
          }
      }
  }
  
  func main() {
      checkNumberRange(1, 65536)
  }
  
  </code></pre>
  
  <p>At the moment the program is crashing with a deadlock at </p>
  
  <pre class="lang-golang prettyprint-override"><code>tmp := &lt;- channel
  </code></pre>
  
  <p>Thanks in advance, Jooarye!</p>