[必读]golang语言报错信息fatal error: all goroutines are asleep – deadlock!

出错信息fatal error: all goroutines are asleep – deadlock!
出错信息的意思是:
main goroutine线,期望从管道中获得一个数据,而这个数据必须是其他goroutine线放入管道的
但是其他goroutine线都已经执行完了(all goroutines are asleep),那么就永远不会有数据放入管道。
所以,main goroutine线在等一个永远不会来的数据,那整个程序就永远等下去了。
这显然是没有结果的,所以这个程序就说“算了吧,不坚持了,我自己自杀掉,报一个错给代码作者,我被deadlock了”
例子:

package main

func main() {
 c := make(chan bool)
 go func() {
 c <- true
 }()
 <-c //这里从c管道,取到一个true
 <-c //这行导致deadlock,因为这时的c管道,永远都取不到数据(注释掉这行就不报错)
}

推荐阅读: 

关于goroutine的理解:http://www.tuicool.com/articles/Efemq2

http://www.cnblogs.com/yjf512/archive/2012/06/06/2537712.html

35 thoughts on “[必读]golang语言报错信息fatal error: all goroutines are asleep – deadlock!

  1. Pingback: w88top

  2. Pingback: เหนียวหนี้ห

  3. Pingback: sen bir oğlansın

  4. Pingback: enlightened marketing

  5. Pingback: ซี ฉัตรปวีณ์ ตรีชัชวาลวงศ์

  6. Pingback: Travel tips

  7. Pingback: มาเด้คอลลาเจน

  8. Pingback: link w88

  9. Pingback: www.cbd-campus.com

  10. Pingback: i99casino

  11. Pingback: Bali,Indonesia

  12. Pingback: baby shark selfie frame

  13. Pingback: sikis izle

  14. Pingback: porn

  15. Pingback: 안전바카라

  16. Pingback: 토토사이트

  17. Pingback: 안전바카라

  18. Pingback: Hadley

  19. Pingback: Furnace Repairs

  20. Pingback: satta king

  21. Pingback: 바카라

  22. Pingback: Dispensary Loans

  23. Pingback: pkv games

  24. Pingback: search

  25. Pingback: cheap viagra 100mg free shipping

  26. Pingback: otc cialis

  27. Pingback: generic ventolin inhalers for sale

  28. Pingback: press release distribution of press release

  29. Pingback: www.spellswork7.com/summer-solstice-spells.html Beauty spells

  30. Pingback: pfizer viagra 50 mg online

  31. Pingback: kalpa pharma testosterone

  32. Pingback: cheapest 100mg viagra delivered overnight

  33. Pingback: Replica Watches Tag Heuer

  34. Pingback: keto diet pills review

  35. Pingback: 출장오피

Comments are closed.