I find a similar question: What does an empty select do?
for{}
will cover 100% cpu usage.
select{}
ask the channel case can read or write or not. But no case in the select. select{}
will use 0% cpu usage? Or just like the for{}
?
for{}
uses 100% CPU because it continuously executes the loop iteration.
select{}
uses nearly 0% CPU because it causes the goroutine to block, which means the scheduler puts it to sleep, and it will never be woken.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With