Why sleeping on a busy-spin zeroes out CPU usage? | بلاگ

Why sleeping on a busy-spin zeroes out CPU usage?

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: -1

I have a thread which usually goes in a busy-spin in certain scenarios:

while (!someFlag)
{
}

Using top in Linux, the CPU usage is >90%.

If I sleep for just 1 second ...

while (!someFlag)
{
   sleep(1)
}

... the CPU usage goes to zero. If I add printfs in the loop, it is clearly showing some activity there, so I'm skeptical on the 0% CPU usage.

Is it really not consuming any CPU cycles?

asked 3 mins ago
Ryuu

...
نویسنده : استخدام کار بازدید : 13 تاريخ : سه شنبه 24 بهمن 1396 ساعت: 8:50