Introduction to common deadlock situations in Golang concurrent operations
This article introduces the relevant knowledge of "introduction of common deadlock situations in Golang concurrent operations". In the operation of actual cases, many people will encounter this dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Catalogue
The first case: the pipeline without cache ability, finish writing and read by yourself.
The second situation: the cooperation journey is late.
The third case: when reading and writing in a pipeline, each other is required to read / write first.
The fourth case: read-write locks block each other, forming an invisible deadlock
What is a deadlock? deadlocks are usually permanently blocked in the Go process. You take my things and ask me to give them to you first and then to me. I take your things and ask you to give them to me first, otherwise I won't give them to you. If we both think so, the matter can't be solved.
The first case: the pipeline without cache ability, finish writing and read by yourself.
Code first:
Func main () {ch: = make (chan int, 0) ch