Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does an empty select do?

Tags:

go

I found the following code in net/http/httptest and wonder what the empty select statement does in Go.

go s.Config.Serve(s.Listener) if *serve != "" {   fmt.Fprintln(os.Stderr, "httptest: serving on", s.URL)   select {} } 
like image 349
Era Avatar asked Sep 06 '13 15:09

Era


1 Answers

An empty select{} statement blocks forever. It is similar to an empty for{} statement.

On most (all?) supported Go architectures, the empty select will yield CPU. An empty for-loop won't, i.e. it will "spin" on 100% CPU.

like image 97
thwd Avatar answered Sep 21 '22 01:09

thwd