本文介绍了将一个空的for循环用作睡眠被优化掉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找了一些code审查和所遇到的忙等待这样:
I am looking over some code to review and have come across a busy wait as such:
int loop = us*32;
int x;
for(x = 0;x<loop;x++)
{
/*do nothing*/
}
我似乎记得读这些空循环可以被优化掉。这是什么会发生在这里还是可以的这项工作?
I seem to recall reading that these empty loops can be optimized away. Is this what would happen here or can this work?
推荐答案
您是在编译器的摆布。事实上,如果它的智能将检测这是一个空操作。顺便说一句,尼尔·巴特沃思有哪里他还谈到了这个问题。
You're at the mercy of the compiler. Indeed if it's smart it will detect it's a noop. Incidentally, Neil Butterworth has a nice post where he also touches on this subject.
这篇关于将一个空的for循环用作睡眠被优化掉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!