当前位置:网站首页>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
边栏推荐
- Global and Chinese markets for laser assisted liposuction (LAL) devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
- Launpad | basic knowledge
- Markdown syntax
- The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
- Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
- What exactly is DAAS data as a service? Don't be misled by other DAAS concepts
- 《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
- 20220701 Barbalat引理证明
- [error record] no matching function for call to 'cacheflush' cacheflush();)
猜你喜欢
How should PMP learning ideas be realized?
Nurse level JDEC addition, deletion, modification and inspection exercise
【LeetCode 42】501. Mode in binary search tree
Jianzhi offer 09 realizes queue with two stacks
How to batch change file extensions in win10
Ehrlich sieve + Euler sieve + interval sieve
Horizon sunrise X3 PI (I) first boot details
Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human
Relationship and operation of random events
随机推荐
Sequence model
Mantis creates users without password options
2022-2028 global tensile strain sensor industry research and trend analysis report
If you can quickly generate a dictionary from two lists
Investment analysis and future production and marketing demand forecast report of China's paper industry Ⓥ 2022 ~ 2028
Awk from getting started to digging in (9) circular statement
China battery grade manganese sulfate Market Forecast and strategic consulting report (2022 Edition)
The map set type is stored in the form of key value pairs, and the iterative traversal is faster than the list set
2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
什么是权限?什么是角色?什么是用户?
HMS core helps baby bus show high-quality children's digital content to global developers
You can see the employment prospects of PMP project management
上周热点回顾(6.27-7.3)
Awk from entry to earth (15) awk executes external commands
Reading notes on how to connect the network - hubs, routers and routers (III)
C语言-入门-基础-语法-[变量,常亮,作用域](五)
《网络是怎么样连接的》读书笔记 - Tcp/IP连接(二)
Global and Chinese market of air fryer 2022-2028: Research Report on technology, participants, trends, market size and share
2022-2028 global optical transparency industry research and trend analysis report
2022-2028 research and trend analysis report on the global edible essence industry