Sobes.tech
Senior

If GOMAXPROCS=2 and two infinite loops with mathematical operations are running, will other goroutines be executed?

sobes.tech AI

Answer from AI

If GOMAXPROCS=2, it means that the Go scheduler can use 2 OS threads simultaneously to run goroutines.

If two infinite loops with intensive mathematical operations are running, they will occupy both threads completely, as they do not make blocking calls or I/O operations.

As a result, other goroutines will not be able to get CPU time, and their execution will be heavily delayed or almost stopped.

To solve such a situation, you need to either reduce the load in these loops, add points where goroutines call runtime.Gosched() or perform blocking operations, or increase GOMAXPROCS to give more threads to the scheduler.

If GOMAXPROCS=2 and two infinite loops with… - sobes.tech