当前位置:网站首页>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 strain gauge pressure sensor industry research and trend analysis report
- 随机事件的关系与运算
- After unplugging the network cable, does the original TCP connection still exist?
- Langage C - démarrer - base - syntaxe - [opérateur, conversion de type] (vi)
- Lauchpad X | 模式
- Awk from entry to earth (14) awk output redirection
- awk从入门到入土(11)awk getline函数详解
- Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
- Trim leading or trailing characters from strings- Trim leading or trailing characters from a string?
- 2022-2028 global edible probiotic raw material industry research and trend analysis report
猜你喜欢
2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report
保姆级JDEC增删改查练习
2022-2028 global protein confectionery industry research and trend analysis report
GoLand environment variable configuration
You can see the employment prospects of PMP project management
C语言-入门-基础-语法-[标识符,关键字,分号,空格,注释,输入和输出](三)
2022-2028 global small batch batch batch furnace industry research and trend analysis report
随机事件的关系与运算
HMS core helps baby bus show high-quality children's digital content to global developers
2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
随机推荐
Launchpad x | mode
Awk from entry to earth (14) awk output redirection
Research and investment strategy report of China's electronic hydrogen peroxide industry (2022 Edition)
Review of last week's hot spots (6.27-7.3)
The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
Horizon sunrise X3 PI (I) first boot details
Awk from entry to penetration (6) regular matching
After unplugging the network cable, does the original TCP connection still exist?
Reload CUDA and cudnn (for tensorflow and pytorch) [personal sorting summary]
"How to connect the network" reading notes - Web server request and response (4)
《网络是怎么样连接的》读书笔记 - FTTH
AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human
LeetCode 74. Search 2D matrix
After unplugging the network cable, does the original TCP connection still exist?
Flutter tips: various fancy nesting of listview and pageview
Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
Lauchpad X | 模式
Investment analysis and future production and marketing demand forecast report of China's paper industry Ⓥ 2022 ~ 2028
Research Report on the development trend and Prospect of global and Chinese zinc antimonide market Ⓚ 2022 ~ 2027
Codeforces Round #793 (Div. 2)(A-D)