Why doesn't infinity loop use cpu processor up to 100

When I run a simple C # program with an empty while loop, my CPU usage increases from 8-12% to 24-20%, and the main usage pattern is almost identical.

    static void Main(string[] args)
    {
        bool flag = true;
        while(flag)
        {

        }
    }

Can anyone explain this behavior. I expected that one main use would be 100% at this time.

Update: I am using an octa-core machine, and the total processor utilization (summing up all core resources) is 25%. And each core (leaving the first) shows a similar usage pattern (about 25%).

enter image description here

+4
source share
2 answers

Because it is single-threaded. You probably have a quad core processor. You are probably maximizing one core.

, . , , .

+3

, . 25%, , .

+2

Source: https://habr.com/ru/post/1653022/


All Articles