Brief introduction
When you use go, you usually use the goroutine, but there are often problems such as the following.
Func Main () {
go dosomething ()
go dosomething ()
}
This type of writing usually causes the program to flash through. At this point it may be necessary to block the main function so that he does not exit. Some would say that you can use an empty for loop like in C + +. This is not possible, go does not allow the use of empty loop statements. using Select
The go language gives a syntactic sugar, which can be implemented by using a SELECT empty statement.
Func Main () {
go dosomething ()
go dosomething ()
select{}
}
This place finds the block () in the runtime by using the assembly code to find the select null in the bottom go compiler. As shown in figure
The Gopark in the source code means that the current goroutine is placed in a wait state.