当前位置:网站首页>Deadlock in channel
Deadlock in channel
2022-07-04 09:17:00 【The diligent bird that flies first】
Situation 1 : In the case of a single thread , Go to channel The amount of data put in exceeds its channel When it comes to the size of
func main(){
var ch = make(chan int, 2)
ch <- 2
ch <- 3
ch <- 8
}
The errors that occur are as follows :
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send]:
main.main()
/Users/lcq/go/src/go_base/gochanneldemo/channeldemo.go:32 +0x8d
Situation two : In the case of a single thread , hold channel After all the data in is taken out , Continue to get data
func main(){
var ch = make(chan int, 2)
ch <- 2
ch <- 3
// ch <- 8
// Start fetching data
fmt.Println(<-ch)
fmt.Println(<-ch)
fmt.Println(<-ch)
}
Error is as follows :
2
3
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
/Users/lcq/go/src/go_base/gochanneldemo/channeldemo.go:36 +0x1c6
Situation three : channel Without closing , Use for range Traversal
func main(){
var ch = make(chan int, 3)
ch <- 2
ch <- 3
// close(ch)
// for range Traverse Also is to channel From the data in
for val := range ch{
fmt.Println(val)
}
// fmt.Println(<-ch)
}
Error is as follows :
2
3
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
/Users/lcq/go/src/go_base/gochanneldemo/channeldemo.go:60 +0xfd
边栏推荐
- 2022-2028 global visual quality analyzer industry research and trend analysis report
- How should PMP learning ideas be realized?
- Analysis report on the production and marketing demand and investment forecast of tellurium dioxide in the world and China Ⓣ 2022 ~ 2027
- Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
- Tkinter Huarong Road 4x4 tutorial II
- Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027
- LinkedList in the list set is stored in order
- Sword finger offer 30 contains the stack of Min function
- Les différents modèles imbriqués de listview et Pageview avec les conseils de flutter
- How to batch change file extensions in win10
猜你喜欢

HMS core helps baby bus show high-quality children's digital content to global developers
![[C Advanced] file operation (2)](/img/50/e3f09d7025c14ee6c633732aa73cbf.jpg)
[C Advanced] file operation (2)

Sequence model

After unplugging the network cable, does the original TCP connection still exist?

2022-2028 global tensile strain sensor industry research and trend analysis report

Jianzhi offer 09 realizes queue with two stacks

LeetCode 74. Search 2D matrix

到底什么才是DaaS数据即服务?别再被其他DaaS概念给误导了
](/img/5a/c6a3c5cd8038d17c5b0ead2ad52764.png)
C语言-入门-基础-语法-[主函数,头文件](二)
](/img/3f/4d8f4c77d9fde5dd3f53ef890ecfa8.png)
C语言-入门-基础-语法-[运算符,类型转换](六)
随机推荐
Horizon sunrise X3 PI (I) first boot details
How do microservices aggregate API documents? This wave of show~
Markdown syntax
"How to connect the network" reading notes - Web server request and response (4)
2022-2028 global protein confectionery industry research and trend analysis report
Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
Flutter tips: various fancy nesting of listview and pageview
Multilingual Wikipedia website source code development part II
The 14th five year plan and investment risk analysis report of China's hydrogen fluoride industry 2022 ~ 2028
Awk from entry to earth (7) conditional statements
Mac platform forgets the root password of MySQL
UML sequence diagram [easy to understand]
C语言-入门-基础-语法-[主函数,头文件](二)
HMS core helps baby bus show high-quality children's digital content to global developers
Target detection -- intensive reading of yolov3 paper
Mantis creates users without password options
Dede plug-in (multi-function integration)
What is uid? What is auth? What is a verifier?
Ehrlich sieve + Euler sieve + interval sieve
Live in a dream, only do things you don't say