I would like to wait on an event in my app which supposed to happen immediately, so I don't want to put my thread on wait and wake it up later.
I wonder what are the difference between using Sleep(0) and hardware pause instruction.
I cannot see any differences of cpu utilization for the following program. My question isn't about power saving considerations.
#include <iostream>
using namespace std;
#include <windows.h>
bool t = false;
int main() {
while(t == false)
{
__asm { pause } ;
//Sleep(0);
}
}
Sleepis a system call, which allows the OS to reschedule the CPU time to any other process, if available, before allowing the caller to continue (even if the parameter is 0).__asm {pause};is not portable.Well,
Sleepis neither, but not on the CPU level but on the system libraries level.