当前位置:网站首页>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
边栏推荐
- Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
- Use Alibaba cloud NPM image acceleration
- Live in a dream, only do things you don't say
- Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
- Awk from getting started to digging in (11) detailed explanation of awk getline function
- You can see the employment prospects of PMP project management
- 2022-2028 global visual quality analyzer industry research and trend analysis report
- Research and investment strategy report of China's electronic hydrogen peroxide industry (2022 Edition)
- Research Report on the development trend and Prospect of global and Chinese zinc antimonide market Ⓚ 2022 ~ 2027
- Review of last week's hot spots (6.27-7.3)
猜你喜欢

Dede plug-in (multi-function integration)

2022-2028 global optical transparency industry research and trend analysis report

Solve the problem of "Chinese garbled MySQL fields"

Codeforces Round #803 (Div. 2)(A-D)

Opencv environment construction (I)

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

Live in a dream, only do things you don't say

AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human

2022-2028 global edible probiotic raw material industry research and trend analysis report

2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
随机推荐
保姆级JDEC增删改查练习
What is uid? What is auth? What is a verifier?
Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
Awk from entry to soil (5) simple condition matching
"How to connect the network" reading notes - Web server request and response (4)
Launchpad x | mode
awk从入门到入土(7)条件语句
Launpad | basic knowledge
Review of last week's hot spots (6.27-7.3)
《网络是怎么样连接的》读书笔记 - Tcp/IP连接(二)
Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
Report on research and investment prospects of polyglycolic acid industry in China (2022 Edition)
Research Report on the development trend and Prospect of global and Chinese zinc antimonide market Ⓚ 2022 ~ 2027
C language - Introduction - Foundation - syntax - [identifier, keyword, semicolon, space, comment, input and output] (III)
Flutter tips: various fancy nesting of listview and pageview
Tkinter Huarong Road 4x4 tutorial II
什么是权限?什么是角色?什么是用户?
If you can quickly generate a dictionary from two lists
What exactly is DAAS data as a service? Don't be misled by other DAAS concepts
【LeetCode 42】501. Mode in binary search tree