In my application, threads need to pause for a very little time (100s of clock cycles). One way to pause is to call nanosleep, but I suppose it requires a system call to the kernel. Now I want to pause without going to the kernel.
Note that I have enough cores to run my threads on and I bind each thread to a separate core, so even an instruction that can halt the core for a little while would be good. I am using x86. I just want the thread to halt while pausing. I don’t want a busy loop or a system call to the kernel. Is it possible to do this? What is the minimum time I can pause a thread?
_mm_pausein a busy-wait loop is the way to go.Unfortunately the delay it provides can change with each processor family:
http://siyobik.info/main/reference/instruction/PAUSE
Example usage for GCC on Linux:
Compile with MMX enabled:
Also you can always just use inline assembler:
From some Intel engineers, you might find this useful to determine the cost of pausing:
http://software.intel.com/en-us/forums/showthread.php?t=48371