It's something terribly non-portable.
In some compilers one of these may works (but you have to check with full optimization enabled, the empty instruction may be thrown away):
for (i = 0; i < spinCount; )
++i; // yes, HERE
or:
for (i = 0; i < spinCount; ++i)
((void)0);
If you're lucky enough then your compiler may provide a macro or an intrinsic function that will compiled to the nop
assembly instruction, something like __noop
in MSVC.
As last resource you can simply add a single assembly instruction (it's compiler dependent, it may be __asm or something like that) to execute...nothing, like this:
for (i = 0; i < spinCount; ++i)
__asm nop
or (check your compiler documentation):
for (i = 0; i < spinCount; ++i)
asm("nop");
EDIT
If you do not have a noop
instruction and you can't add assembly code (I'm sorry, what kind of compiler you're using?) you can rely on the assumption that an instruction with a side effect won't be optimized away (or, as posted by @ouah, an access to a variable declared volatile
).